SO essentially Im working on a top down 3d shooter, and I have a ship that I want to move side to side and up and down, I HAVE THIS WORKING, but there is a new feature that I would like to add, I would like the ship to rotate towards the direction that it is turning and then when the user is done turning it goes back to its original rotation orientation.
Here is my code so far
using UnityEngine; using System.Collections;
public class PlayerScript: MonoBehaviour { // players lives private int playerLife = 5; private float speed = 8.0f; private int missleCount = 3; public float rotateSpeed;
public static int playerScore;
//public static int missles;
public Rigidbody projectileBullet;
public Rigidbody projectileMissle;
void OnGUI()//Works with the GUI interface
{
//Score that shows on screen
GUI.Label(new Rect(10,10,200,50), "Score: " + playerScore);
//Players Life
GUI.Label(new Rect(10,30,200,50), "Lives: " + playerLife);
GUI.Label(new Rect(10, 50, 200, 50), "Missles: " + missleCount);
}
public int getPlayerLife
{
get{ return playerLife;}
}
public float getSpeed
{
get{ return speed;}
}
// Update is called once per frame
void Update ()
{
//amount to movement
float movementHorizontal = (speed * Input.GetAxis("Horizontal")) * Time.deltaTime;
float movementVertical = (speed * Input.GetAxis("Vertical")) * Time.deltaTime;
transform.Translate(Vector3.right * movementHorizontal);
//translate the player Horizontaly
transform.Translate(Vector3.right * movementHorizontal);
//translate vertically
transform.Translate(Vector3.up * movementVertical);
if (transform.position.x <= -7.5)
{
transform.position = new Vector3(7.4f, transform.position.y, transform.position.z) ;
}
else if (transform.position.x >= 7.5)
{
transform.position = new Vector3(-7.4f, transform.position.y, transform.position.z);
}
if (Input.GetKeyDown(KeyCode.Space))
{
Rigidbody cloneBullet;
cloneBullet = Instantiate(projectileBullet, transform.position, transform.rotation) as Rigidbody;
}
if (Input.GetKeyDown(KeyCode.LeftShift) || Input.GetKeyDown(KeyCode.RightShift))
{
Debug.Log(missleCount);
if (missleCount >= 0 && missleCount != 0)
{
--missleCount;
Rigidbody cloneMissle;
cloneMissle = Instantiate(projectileMissle, transform.position, transform.rotation) as Rigidbody;
}
}
}
}