Game Development Community

WorldLimit Wrap?

by Phillip "Renolc" Gibson · in Torque Game Builder · 03/26/2005 (7:33 pm) · 24 replies

While reading through the T2D Reference Doc, I noted the listing of "WRAP" as a valid limitMode for the WorldLimit. This would be perfect for my asteroids clone I'm working on, but after trying this, the console gave me this warning
fxSceneObject2D::setWorldLimit - Invalid World Limit!
and the player ship did not wrap.

This is my exact code for the createPlayer function
function createPlayer()
{
	$player = new fxStaticSprite2D() { scenegraph = t2dSceneGraph; };
	$player.setGroup( 1 );
	$player.setLayer( 1 );
	$player.setPosition("0 0");
	$player.setSize("5 5");
	$player.setImageMap( player );
	$player.setWorldlimit( wrap, "-50 -40 50 40", true );
	$player.setCollisionActive( true, false );
	$player.setCollisionMasks( BIT(2), BIT(2) );
	$player.setCollisionCallback( true );
	$player.setMaxLinearVelocity( 20 );
	$player.setMaxAngularVelocity(180);
	$player.setCollisionPolyCustom( 3, "-0.6875 -0.6875 0.96875 0 -0.6875 0.6875");
	$player.fireLinkPoint = $player.addLinkPoint("0.96875 0");
	$player.tag = "player";
}
Am I doing something wrong? Or, is there another way I could get my player to wrap after hitting the world limit (ie. go past the right side of the screen and apear from the left side)?
Page «Previous 1 2
#1
03/26/2005 (7:59 pm)
Not so sure about the wrap mode, but another way to do this would be to use the onWorldLimit callback (pg.8 of the reference doc).

This is made doubly useful since the callback also returns which limit was hit (left, right, top, bottom). So, based on which limit, change the pop the player over to the opposite limit. Bit of a hack, I admit, but it's an alternative to think about if Wrap doesn't work.
#2
03/26/2005 (8:01 pm)
I believe I saw Wrap suggested for worldLimit in another thread and Melv sounded pretty upbeat about it.
#3
03/26/2005 (8:06 pm)
Thanks for the info. I'll look into the onWorldLimit callback. God as my witness, I shall have wrapping finished before the night is done! =)
#4
03/26/2005 (8:56 pm)
I'm still having just a little bit of trouble. My wrapping code looks like this:
function fxSceneObject2D::onWorldLimit(%this, %limitMode, %wall)
{
	%thisPos = %this.getPosition();
	%thisPos.x = getWord(%thisPos, 0);
	%thisPos.y = getWord(%thisPos, 1);

	if(%wall $= "top")
	{
		%this.setPosition(%thisPos.x SPC "40");
	}
	if(%wall $= "bottom")
	{
		%this.setPosition(%thisPos.x SPC "-40");
	}
	if(%wall $= "right")
	{
		%this.setPosition("-50" SPC %thisPos.y);
	}
	if(%wall $= "left")
	{
		%this.setPosition("50" SPC %thisPos.y);
	}
}
And it seems to work _sometimes_ (most of the time when I run into the top wall on the right half of the screen). But the other times my ship simply flies off screen and dosen't wrap back from the opposite side.

EDIT: Thought I also should mention that the world limits on this ship are from "-56 -46 56 46" with the camera viewing 100 width/80 height, I have the onWorldLimit callback set to true, and my ship has a custom 3 sided collision poly.
#5
03/26/2005 (9:05 pm)
I think that is happening because your ship may be moving so fast that it doesn't collide with the world limit. To solve a similar issue on my tetris game, I made a few "collision buffers" that were bigger than the object itself, but always had the same orientation. Does it only happen when you are zooming around or does it sometimes happen when you are moving slow? Your implementation is how I would have handled it though, so it looks right.
#6
03/26/2005 (9:14 pm)
As default, my ship has a MaxLinearVelocity of 20. But just to be sure, I tried it at both 10 & 5 also. No difference in my results -- works on the right half of the top wall, but most every where else dosen't.
#7
03/26/2005 (9:23 pm)
I just noticed that when the wrap fails, it spams my console with "Invalid Number of Parameters!" so it must be something wrong with when I set the players new position. But I can't for the life of me figure out what's wrong with it. And once more, how can it have and 'invalid number of parameters' on the left half of the screen, but not the right?

My head hurts >.<

EDIT: Well, I'm going to call it a night. I'll work on this tomorrow. Happy early Easter everyone!
#8
03/27/2005 (9:29 am)
The collision system uses swept polygons, which should never miss a collision no matter how fast your object is moving. $.02
#9
03/27/2005 (11:42 am)
~bump~
I still can't seem to get this to work right.
img.photobucket.com/albums/v161/iamnotphillip/other/wrapTroubles.pngThe areas I have marked as green are currently working. Everywhere else simply spams my console with warnings. Does anyone have any idea how to fix this? I will provide my full client.cs if I have to.
#10
03/28/2005 (1:20 am)
Philip,

"wrap" mode was taken out because it was causing problems. Things that were causing problems and we didn't have time to fix just got culled for the initial release, like alot of things.

It will be added back in though.

- Melv.
#11
03/28/2005 (5:49 am)
No offense Melv (I realise you are probably very busy), but we already figured that out. ;)

What I now need help with is my self-implimented wrapping system (see info in my above posts) which, for some reason, refuses to work. Any help would be greatly appreciated, although if you are simply unable to due to work or family, then I totally understand. They are much more important than my petty problems. =)
#12
03/28/2005 (6:30 am)
Disclaimer: Haven't had caffeine yet!

Ahem.. To start with, have you turned on trace so you can follow the calls and see if anythign unusual is going on?
#13
03/28/2005 (6:38 am)
Probably not, seeing that I have no idea what trace is.
>.>
<.<

I'm still a TorqueScript n00b. =P
#14
03/28/2005 (6:47 am)
In your console:

trace(1);

trace(0); to turn it off.

You may want to put in some echos to make sure that %this is actually your ship, and not something else (it probably is, but it's somewhere to start!).
#15
03/28/2005 (9:49 am)
It's been a day or two, so I don't know if you're still having the "invalid number of parameters" problem, but one thing that strikes me is this:
%thisPos = %this.getPosition();
%thisPos.x = getWord(%thisPos, 0);
%thisPos.y = getWord(%thisPos, 1);
getPosition() returns a string, not an object, so, even though the console doesn't complain, referring to %thisPos.x has no real effect. The result is that %this.setPosition(%thisPos.x SPC "40"); boils down to %this.setPosition(" 40"); and results in the invalid number of parameters complaint.

Hope that helps.
#16
03/28/2005 (1:41 pm)
@Stephen:
So simple. I should have thought of that. =)
Anyways, I tried the trace, and everything seems to be working fine. That is, until I hit one of the walls that have never worked in the first place, then it spams "fxSceneObject2D::setPosition - Invalid number of parameters!" Also, the player ship is the onlything I have in the game right now, so it couldn't possibly be anything else just yet. But I did go ahead and add in an echo. "Player has hit the left wall!" =)

@Matt:
This is where my main problem lies. What you said sounds right, but then again, why does the way I currently have it work _sometimes_? I would have thought it would work all the way, or not at all. I made a simple function...
function testPos( %this )
{
	%thisPos = %this.getPosition();
	%thisPos.x = getWord(%thisPos, 0);
	%thisPos.y = getWord(%thisPos, 1);
	echo("O:" SPC %this.tag);                    // Object
	echo("P:" SPC %this.getPosition());          // Position
	echo("X:" SPC %thisPos.x);                   // PositionX
	echo("Y:" SPC %thisPos.y);                   // PositionY
}
...to test this and my results are somewhat surprising.

==>testPos($player);
O: Player
P: 0.000000 0.000000
X: 
Y: 
==>testPos($player);
O: Player
P: 1.662697 0.000000
X: 
Y: 
==>testPos($player);
O: Player
P: 2.690413 0.000000
X: 
Y: 
==>testPos($player);
O: Player
P: 3.331295 0.000000
X: 3.331295
Y: 0.000000
==>testPos($player);
O: Player
P: 4.096284 0.000000
X: 4.096284
Y: 0.000000
==>testPos($player);
O: Player
P: 4.933990 0.000000
X: 4.933990
Y: 0.000000
==>testPos($player);
O: Player
P: 5.774606 0.000000
X: 5.774606
Y: 0.000000
==>testPos($player);
O: Player
P: 13.925462 -1.584773
X: 13.925462
Y: -1.584773
==>testPos($player);
O: Player
P: 16.996836 -2.524995
X: 16.996836
Y: -2.524995
==>testPos($player);
O: Player
P: 21.210230 -3.814820
X: 21.210230
Y: -3.814820
==>testPos($player);
O: Player
P: 24.272943 -4.752349
X: 24.272943
Y: -4.752349
==>testPos($player);
O: Player
P: -14.361778 8.161232
X: 
Y: 
==>testPos($player);
O: Player
P: -13.214958 12.751455
X: 
Y: 
==>testPos($player);
O: Player
P: -11.846233 18.229956
X: 
Y:
It appears that the way I'm doing it works for slightly less than half of the screen, while the rest returns blank variables (just as you said). This potentially may be a bug in T2D, although it is more likely to be something wrong with my own code.

Since the way I was planning on implimenting wrapping dosen't seem to be working, is there another way I could possibly do this? I may end up just having to alter my original ideas for the game. Not that big of a problem, really. It should work well either way.
#17
03/28/2005 (1:58 pm)
This works for me
%thisPos = %this.getPosition();
   %thisPosX = getWord(%thisPos, 0);
   %thisPosY = getWord(%thisPos, 1);
   echo("O:" SPC %this.tag);                    // Object
   echo("P:" SPC %this.getPosition());          // Position
   echo("X:" SPC %thisPosX);                   // PositionX
   echo("Y:" SPC %thisPosY);                   // PositionY

this works also

%thisPos = new ScriptObject();
   %thisPos.pos = %this.getPosition();
   %thisPos.x = getWord(%thisPos.pos, 0);
   %thisPos.y = getWord(%thisPos.pos, 1);
   echo("O:" SPC %this.tag);                    // Object
   echo("P:" SPC %this.getPosition());          // Position
   echo("X:" SPC %thisPos.x);                   // PositionX
   echo("Y:" SPC %thisPos.y);                   // PositionY
#18
03/28/2005 (1:59 pm)
I doubt local variables... "%thisPos" were made to have sub values ...
#19
03/28/2005 (1:59 pm)
function testPos( %this )
{
	%thisPos = %this.getPosition();
	%thisPosx = getWord(%thisPos, 0);
	%thisPosy = getWord(%thisPos, 1);
	echo("O:" SPC %this.tag);				// Object
	echo("P:" SPC %this.getPosition()); // Position
	echo("X:" SPC %thisPosx);           // PositionX   
	echo("Y:" SPC %thisPosy);           // PositionY
}

Try it with this function instead.

I'm going to guess that the scripting engine is getting confused with the %thisPos.x and %thisPos.y variables.
#20
03/28/2005 (2:01 pm)
Try this code

function testPos( %this )
{
   %thisPos = %this.getPosition();
   %Pos.x = getWord(%thisPos, 0);
   %Pos.y = getWord(%thisPos, 1);
   echo("O:" SPC %this.tag);                    // Object
   echo("P:" SPC %this.getPosition());          // Position
   echo("X:" SPC %Pos.x);                   // PositionX
   echo("Y:" SPC %Pos.y);                   // PositionY
}
Page «Previous 1 2