Game Development Community

SetWorldLimit

by Robert Ota Dieterich · in Torque Game Builder · 06/20/2005 (5:27 pm) · 10 replies

Say, ever consider setting up setWorldLimit() so you can give at a particular function to be called when the world limit is hit? Maybe something like:

$player.setWorldLimit( playerStop(), "-50 -40 50 40" );

function playerStop() 
{
	$player.setLinearVelocityX(0);
        $player.setLinearVelocityY(0);
	$player.playAnimation( playerFallOver );
}

I guess you'd probably also need to define the function to accept some value from setWorldLimit() to identify which limit is being hit, but I think you get the idea.

-Rob

P.S. Good work on T2D though, by the way. I'm really enjoying working with it.

#1
06/20/2005 (8:28 pm)
There is already fxSceneObject2D::OnWorldLimit() callback actually. it works similarly to onCollision, and is actually listed right after it in the documentation.
#2
06/22/2005 (7:58 pm)
Why so it is. Thanks a lot.

Back to hacking some TorqueScript I go.

-Rob
#3
06/23/2005 (8:38 am)
Something for the future that might be cool is multiple world limits. I guess they wouldn't be limits as much as callback triggers. Eh, well, it just popped into my head when I read this, and so there it is now. :) I'll get back to work.....
#4
06/23/2005 (8:48 am)
You can set world limits for each individual object, or is there something else you wanted to do?

<blah blah define sprites for Player1, Player2, nme1, nme2>
  
	$player1.setWorldLimit( clamp, "-80 -80 80 80" );
	$player2.setWorldLimit( clamp, "-80 -80 80 80" );
	$nme1.setWorldLimit( kill, "-80 -80 80 80" );
	$nme2.setWorldLimit( bounce, "-80 -80 80 80" );
#5
06/23/2005 (1:58 pm)
I meant setting more than 1 limit to trigger more than 1 callback. It's just a passing thought, nothing I'm specifically trying to accomplish. :)
#6
06/24/2005 (5:41 am)
In regards to programming specific functions to fire on onWorldLimit callbacks for specific objects, you could do:


function createPlayer() {
                $player = new fxStaticSprite2D() { scenegraph = t2dSceneGraph; };
                // other init code deleted for brevity

                // define special on world limit callback method
                $player.owlCB = "playerStop";   
}

function createBugEnemy() {
                $benemy= new fxStaticSprite2D() { scenegraph = t2dSceneGraph; };
                // other init code deleted for brevity
                 
                // define special on world limit callback method
                $benemy.owlCB = "enemyStop"; 
}


function fxSceneObject2D::onWorldLimit( %Obj.......){ 
        if (!(%Obj.owlCB $= "") ) {   
                call(%Obj.owlCB);        
        }        
}

function playerStop() {   
       //................
}

function enemyStop() {   
       //................
}
#7
09/08/2005 (11:20 pm)
@Ty: I haven't had any luck getting the method you have listed here for calling a script function when 'onWorldLimit' occurs to work. When I input the code, it quite literally does nothing. No script error's or anything like that. Here is my codde:

In the object...
%enemy.activeShip.destroyOnWorldLimit = true;
  %enemy.activeShip.setWorldLimit( null, $worldController.globalWorldLimit);

Then for the onWorldLimit...
function fxSceneObject2D::onWorldLimit( %this, %mode, %limit )
{
  if(%this.destroyOnWorldLimit  == true)
     error("Poit");
}

The word 'poit' is never echo'ed to the screen. I have tried a number of things in place of 'null' in the setWorldLimit method, however everything does exactly as they are supposed to as said by the documentation, and ignore my code entierly. I have even attempted created 'onWorldLimit' as a method for my object in hopes that it would override the onWorldLimit that fxSceneObject2D uses, but no luck there.
#8
09/09/2005 (6:46 am)
Dave,

You need to specify the third parameter in "setWorldLimit()" to true (it defaults to false) which specifies whether to action the callback or not.

Hope this helps,

- Melv.
#9
09/12/2005 (5:04 pm)
The man himself answers my plea for help! =)

That did the job, Melv! Thanks a lot!!

-Dave C.
#10
09/14/2005 (12:07 am)
No probs, here to help. :)

- Melv.