Moving an object with rotation on just one axis.

I’m creating an asteroid Dodging game with the simple point of scoring points the more asteroids you dodge. I’m using the Unity standard to rotate my ship giving the illusion of banking however when I also apply movement to this the ship moves in the direction of the rotation i.e: when I bank left the ships position is moving parallel to the angle so if it is now angled left the ship will now move down and left(-x & -y) the opposite if I bank right the ship will move south east (down and left) which is not what I wish for. I would like my ship to bank left and right but stay on the same y position and only move left and right . My current movement code is below:

`
using UnityEngine;

using System.Collections;

public class shuttleControl : MonoBehaviour {

float speed = 50f;

public float tiltAngle = 30.0F;
public float smooth = 2.0F;
// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update () {

float h = Input.GetAxis("Horizontal") * Time.deltaTime * speed;

float tiltAroundZ = Input.GetAxis("Horizontal") * tiltAngle;

Quaternion target = Quaternion.Euler(0, 0, tiltAroundZ);
transform.rotation = Quaternion.Slerp(transform.rotation, target, Time.deltaTime * smooth);
transform.Translate(-h,0,0);

}
}`

My question is the following: seeing the above code, how could i force my ship to move just on the X axis only but keep the tilted rotation? so it will bank left and right and only move left and right?

Thanks,

Euden

I’m guessing here, but I expect the center of rotation for you ship is not at the center of the ship. As a quick test, replace your ship with a cube and test the rotation. If the cube rotates correctly but the ship “moves,” then you have a center problem. If you modeled the ship yourself, you can simply move the center point in your modeling program. If that is not an option, you can make the change using an empty game object. Create and empty game object and place it at the point you want the ship to rotate around. Make the ship the child of the empty game object. Then put your rotation code on the empty game object.