- Home /
The wrong Axis?
Is there anyway to ensure that I can send my object flying backwards from the way it is currently facing? For instance I tried this :
var backward; backward=Vector3(0,0,-10);
function Knockback(direction : Vector3,duration : float,speed : int)
{
var startTime = Time.time;
while(Time.time < (startTime + duration))
{
charController.SimpleMove(direction*speed);
yield;
}
}//end function
However all this does is send my object flying in the same direction, no matter where it is facing.
Answer by aldonaletto · Aug 30, 2011 at 02:15 AM
The transform has 3 vectors relative to its orientation: transform.forward, transform.up and transform.right. In your case, use -transform.forward: it's equivalent to "transform.backward":
charController.SimpleMove(-transform.forward*speed);NOTE: Don't set the direction vector outside your function, because it will be freezed at the initial character orientation (instructions outside any function are executed only once at initialization).
That helped greatly thank you. I still have a problem though. Whenever I rotate the Y axis(which should be the vertical axis correct?) of my object, the object moves left to right. Whenever I rotate the X axis, my character will rotate to a headstand. Is that how it's supposed to work?
If I got correctly what you're saying, it's ok: the x, y and z parameters of Rotate or other rotation functions are the angles around the corresponding axes. Rotate(0,30,0), for instance, rotates 30 degrees around the Y axis, so the rotation is horizontal. The same applies to Rotate(30,0,0): it will rotate around X, what moves in the vertical plane.
Ah.. Okay. I thought something was very wrong... lol Thanks.