Game Development Community

Vector<---i am always wrong..

by Kenny · in Torque Game Builder · 03/03/2007 (6:28 am) · 1 replies

Function Enemy::Move(%this,%vx,%vy)
{
%this.setLinearVelocity(%vx, %vy);
%theAngle=t2dAngleBetween(%vx 0,0 %vy);
%this.setRotation(%theAngle/2);
echo(%theAngle);
}


what;s wrong with that script above?
i try to get angle between x y vector ,then rotate the ship to let it face the right direction.
t2dAngleBetween(%vx 0,0 %vy); <---it's always wrong. i don;t know why.

#1
03/03/2007 (7:49 am)
Well, you form vectors in Torquescript as space delimited strings, so that line should look like this:
%theAngle=t2dAngleBetween(%vx SPC "0", "0" SPC %vy);
}

Hopefully that'll work - it might return in radians too, so you should convert it before using it to set the Rotation.

Hope that helps!