Does this look efficient, or is there a better way?
by Neil Petrick · in Torque Game Builder · 09/20/2006 (1:18 pm) · 3 replies
I wanted to have the fish in the fish demo start out with random directions... didn't like the look of them all starting facing the same way. So I added this function:
and changed the OnLevelLoaded function call:
I'm not sure how torquescript handles variables yet so I just used the pointer references.
Any suggestions?
function FishClass::setDirection(%this)
{
%this.direction = getRandom(0, 1);
switch (%this.direction)
{
case 0:
%this.direction = true;
%this.speed = -%this.speed;
case 1:
%this.direction = false;
}
}and changed the OnLevelLoaded function call:
function FishClass::onLevelLoaded(%this, %scenegraph)
{
%this.setSpeed();
%this.setDirection();
%this.setFlipX(%this.direction);
%this.setLinearVelocityX(%this.speed);
}I'm not sure how torquescript handles variables yet so I just used the pointer references.
Any suggestions?
About the author
#2
09/20/2006 (2:22 pm)
It works exactly as I intended. I just know none of the available methods so I have no idea if I what I did was efficient or if there was a better way.
#3
You did it exactly the way I have done it in the past, but that doesn't necessarily mean it's the perfect way, hehehe.
Short Answer--looks great, move on to your next item!
09/20/2006 (2:53 pm)
It might be possible to squeeze out some form of optimization somehow, but I'm not aware of anything obvious.You did it exactly the way I have done it in the past, but that doesn't necessarily mean it's the perfect way, hehehe.
Short Answer--looks great, move on to your next item!
Torque 3D Owner Stephen Zepp