Weird Clamp command issues.
I try to build an fork lift and i need some clamping for the lift(y) and the fork(x).
Each time my fork reach the clamping limit; my fork move on Y or Z for no reason. How i can fix this ?
video showing the bugs : link text link text
There the script i use.
using UnityEngine;
using System.Collections;
public class mathftutor : MonoBehaviour {
public Transform pos;
private float mover;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update ()
{
//this is used to get use left and right arrow input
mover = Input.GetAxis ("Horizontal Right") * Time.deltaTime * 20;
//now we use translate to move the character
transform.Translate (mover, 0, 0);
transform.position = new Vector3 ((Mathf.Clamp (transform.position.x, -2, 2)), transform.position.y, transform.position.z);
}
}
Comment
You are setting position twice:
transform.Translate (mover, 0, 0);
transform.position = new Vector3 (($$anonymous$$athf.Clamp (transform.position.x, -2, 2)), transform.position.y, transform.position.z);
Your answer
![](https://koobas.hobune.stream/wayback/20220612044451im_/https://answers.unity.com/themes/thub/images/avi.jpg)