i wrote a script for clamping the xvalues but when i run the script the clamp is ignored. can anyone explain why.
using UnityEngine;
using System.Collections;
public class player_movement : MonoBehaviour {
public float speed = 2;
private float xLeftLimit = -1.642209f;
private float xRightLimit = 1.626122f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
float amtToMoveXdir = Input.GetAxis("Horizontal") * speed * Time.deltaTime;
float amtToMoveXdirClamp = Mathf.Clamp(amtToMoveXdir, xLeftLimit, xRightLimit);
transform.Translate(Vector3.right * amtToMoveXdirClamp);
float amtToMoveZdir = Input.GetAxis("Vertical") * speed * Time.deltaTime;
transform.Translate(Vector3.forward * amtToMoveZdir);
//float XmovementClamp = Mathf.Clamp(amtToMoveXdir, xLeftLimit, xRightLimit);
}
}
i think it should work, check the clamp rang higher
– Moorno it is moving out of the range.
– galaboythanks moor and alucardj for the help.
– galaboy