So i tried to make a simple cannon game where player could move arround the cannon with their mouse, so i tried to rotate the cannon via eulerangle and Mouse X, here’s the complete code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class tesScript : MonoBehaviour
{
public Transform baseObject;
public Transform barrel;
public float minXroation;
public float maxXrotation;
public float minYrotation;
public float maxYrotation;
public float kecepatanRotasi;
// Update is called once per frame
void Update()
{
aimCannon();
}
void aimCannon()
{
float rotasiBaseBaru = baseObject.localRotation.eulerAngles.y + kecepatanRotasi * Input.GetAxis("Mouse X");
rotasiBaseBaru = Mathf.Clamp(rotasiBaseBaru, minYrotation, maxYrotation);
baseObject.localRotation = Quaternion.Euler(0,rotasiBaseBaru,0);
}
}
without the Clamp, the cannon is properly work! but when i use the math clamp, it doesn’t work properly with the limit i gave and instead when the cannon try to reach the minXrotation value, the cannon is flicking and back to the maxXrotation value.
i tried this code before on my older project and it works fine, but now i can’t find the difference between code and inspector settings but yet this bug appear.