So I’m working on a game where you’re in space with a jetpack, and I’m having problems with the movement. I want to be able to have him move forward and continue in that direction regardless of which way he is facing, but when you move forward again, he moves forward in his own local space, but to continue moving that direction in world space. I can either get him to move in local space, and stay moving in local space, or get him to move in world space, and stay moving in world space. I want to know how to do both simultaniously.
var speed = 1.0;
var acceleration = 0.5;
var x = 0.0;
var y = 0.0;
var z = 0.0;
function Update () {
var forward = Input.GetAxis("Vertical") * Time.deltaTime * speed;
var sideways = Input.GetAxis("Horizontal") * Time.deltaTime * speed;
if(forward>0) {
z = z+acceleration; }
else if (forward<0){
z = z-acceleration; }
if(sideways>0) {
x = x+acceleration; }
else if (sideways<0) {
x = x-acceleration; }
transform.Translate(x,y,z,Space.World);
}
I’m still new to much of Unity and it’s coding, so any help would be appreciated. Thanks!