- Home /
How would I Limit the position of the Z axis Transform?
Hello:
I am creating a 2dUnity Game. My players z position keeps increasing when the game starts and I don't know why .My player falls through the background when his Z transform is above 48, how would I be able to limit the z max position? Thankyou
using UnityEngine;
using System.Collections;
public class carController : MonoBehaviour {
Vector3 position;
public float Speed = 2f;
public float maxPos = 5.0f;
void Start() {
}
void Update ()
{
transform.Translate (Input.acceleration.x,0, -Input.acceleration.x);
var pos = transform.position;
pos.x = Mathf.Clamp (transform.position.x, -5.0f, 5.0f);
transform.position = pos;
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220611231619im_/https://answers.unity.com/themes/thub/images/avi.jpg)