transform.translate limits
Hi, im struggling to add limits to a robotic arm I have made.
it moves using different buttons/ joysticks on a xbox controller. I want to limit its movement so it doesn't clash with walls etc, so I have tried to add that the position has to be below 10 on the z axis.
if (Input.GetAxis("XboxLeftJoystickX") > 0 && Gantry.gameObject.transform.position.z < 10)
Gantry.gameObject.transform.Translate(Vector3.forward * 0.5f * Time.deltaTime);
but this doesn't work, can anyone help, I just need to know the best way of limiting these movements.
Also working the other way obviously
if (Input.GetAxis("XboxLeftJoystickX") < 0 && Gantry.gameObject.transform.position.z > -10)
Gantry.gameObject.transform.Translate(Vector3.back * 0.5f * Time.deltaTime);
Answer by Lee-Tarry · Sep 13, 2019 at 07:52 AM
If anyone finds this thread looking for an answer its pretty simple I fixed it using transform.localposition e.g. if (Input.GetAxis("XboxLeftJoystickX") > 0 && Gantry.gameObject.transform.localposition.z < 10) Gantry.gameObject.transform.Translate(Vector3.forward 0.5f Time.deltaTime);
Your answer
Follow this Question
Related Questions
How to translate an object in an unknown angle ? 1 Answer
GameObject doesn't move 1 Answer
transform.Translate is too smooth 3 Answers
Diagonal character movement 0 Answers
How to move gameObject along a Vector3 with OnMouseDrag()? 0 Answers