trying to get this script to work rotating a cube smoothly on x and y with max and min clamps on y axis, cube dont want to react, cant seem to get it to move, any help much appreciated thank you
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NewBehaviourScript : MonoBehaviour {
public GameObject GUN;
public float stationaryRotationSpeed = 170.0f;
public float _hor = 0f;
public float _easeStrength = 0.001f;
public float RSPEED = 170.0f;
public float ROL = 0f;
public float ACCEL = 0.001f;
private float MINANGLE = 280;
private float MAXANGLE = 358;
float k = 0.0f;
Vector3 myRotation;
// Use this for initialization
void Start () {
myRotation = GUN.transform.rotation.eulerAngles;
myRotation.x = MAXANGLE;
}
// Update is called once per frame
void Update () {
var p = Input.GetAxis("Mouse X");
_hor = Mathf.Lerp(_hor, p, _easeStrength);
float rotation = _hor * stationaryRotationSpeed * Time.deltaTime;
GUN.transform.Rotate(0, rotation, 0);
var k = -Input.GetAxis("Mouse Y");
ROL = Mathf.Lerp(ROL, k, ACCEL);
float ROTATION = ROL * RSPEED * Time.deltaTime;
myRotation.x += ROTATION;
myRotation.y += rotation;
myRotation.x = Mathf.Clamp(myRotation.x, MINANGLE, MAXANGLE);
GUN.transform.eulerAngles = myRotation;
Vector3 eulerAngles = GUN.transform.rotation.eulerAngles;
Debug.Log("GUN.transform.rotation angles x: " + eulerAngles.x + " y: " + eulerAngles.y + " z: " + eulerAngles.z);
}
}