Hi,
I’m a beginner in Unity . I have a question: In my game I have tank with rotatable turret but I have problem with gun. I mean , it’s possible to rotate cannon in y angle but i wanted to limit this for example -15/24
Turret Rotation
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TurretRotation : MonoBehaviour
{
public float horizontalSpeed = 2.0F;
void Update() {
float h = horizontalSpeed * Input.GetAxis("Mouse X");
transform.Rotate(0, 0, h);
}
}
Gun Rotation
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GunAngle : MonoBehaviour
{
public float verticalspeed = 20.0F;
void Update()
{
float v = verticalspeed * -Input.GetAxis("Mouse Y");
transform.Rotate(v * 5*Time.deltaTime, 0, 0);
}
}
I searched many similiar question on this site but nothing work for me…alsoI don’t understand.quaternions and some people say that it is needed. What I can do?