Hello I was looking for some help on how to set my player game objects movements. Essential the player is a stationary turret in the middle of the map and I just need to make it move left and right.
Now I have made it so that is rotates but it is currently rotating 360 degrees and I simply need to to go 90 degrees to the right and 90 degrees to the left…
This is what I currently have for script and it doesn’t seem to be working correctly - please help:
using UnityEngine;
using System.Collections;
public class playerMovement : MonoBehaviour
{
public float speed ;
public float rotationSpeed;
//transform
Transform myTrans;
//object position
Vector3 myPos;
//object rotation
Vector3 myRot;
//object rotation
float angle;
// Use this for initialization
void Start ()
{
myTrans = transform;
myPos = myTrans.position;
myRot = myTrans.rotation.eulerAngles;
}
void FixedUpdate ()
{
//rotate object Right & Left
if (Input.GetKey (KeyCode.RightArrow)) {
myRot.z -= rotationSpeed;
}
if (Input.GetKey (KeyCode.LeftArrow)) {
myRot.z += rotationSpeed;
}
if (transform.eulerAngle.x > 90) {
transform.eulerAngle.x = 90;
}
myTrans.position = myPos;
myTrans.rotation = Quaternion.Euler (myRot);
}
}