- Home /
Clamp position x and z based on local x and z position
I don't need to clamp it on x and z in world space , I need it in local space like shown in the photo. I don't actually want to clamp it to a value , i want it to be infinite just not to move on the x and z world space only locally.
I need it to lock the position on the local x and z axis at runtime
Vector3 tempVar = transform.position;
tempVar.x = 0f;
transform.position = tempVar;
This locks the position to his world x and i set it to 0 as an example i need that for x and z but local position not world . Clamp it so it doesn't go on world x and z but goes on local x and z in any direction Im not moving the object in any way just want to clamp it so it doesn't go on world x and z
Your question is not very clear. You want the object to be moved only on its X & Z local axes?
Do you want to constraint this in edit mode or at runtime. If you want to constraint the position at runtime, you will need to edit your question and provide your code responsible for moving the object.
I want this to happend at runtime , I want to lock the box position based on his local x and z , I want it to move only in directions on the photo not on his world x and z. (Not in edit mode by switching to local)
Answer by AxonGenesis · Nov 23, 2019 at 05:15 PM
Just change your code to use localPosition. The world position will be inherited from the parent.
Vector3 tempVar = transform.localPosition;
tempVar.x = 0f;
transform.localPosition = tempVar;
Doesn't seem to be working it still locks it in a world position, I even tried puting the object in another object still the same result.
Your answer
![](https://koobas.hobune.stream/wayback/20220612215214im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Clamp rotation of value from other object 0 Answers
How to cap this movement? 1 Answer
object transform and clamp in local direction 0 Answers
Prevent Object from going out of Circle Radius 3 Answers
Clamping rigidbody's Z position causing issues in the editor, when transform hits zero on Z axis 0 Answers