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.
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).