I’m assuming this question has already been answered a hundred times before, but I can’t seem to find an answer. Upon moving a plane which must move directly forward at a velocity of (0,0,1) in world space at all times, I am unable to keep the plane from losing forward velocity whilst simulating movement via angles. Is there any way to keep the object sustaining at a speed regardless the angle it is moving on?
This is just a maths question, right? If your plane is flying in the z direction at 1 unit/second all is good. If if turns and flies at 45 degrees to the z axis and keeps moving at 1unit/second then it’s flying at cos(45) in the z axis. (I am basically projecting the new direction onto the z-axis, effectively taking a dot product.) So to maintain a speed of 1 in the z-axis you need to divide by cos(45), or multiply the plane’s speed by 1.4. Generalising, as the angle changes to theta adjust the speed by dividing by cos(theta). (Since cos always returns a value less than one, dividing by cos(theta) will always increase the plane’s speed.)
This will move it along the Z world axis. I’m not sure how well this works with most things though.
Works if your object is always changing its local rotations and what not.
var speed : float = 5.0;
directionForward = Vector3.forward * Time.deltaTime * speed;