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