# Restricting movement on an axis from physics

 0 I want enemies and objects to not move on the y-axis on account of physics, but I want to still be able to move them at will, such as in their update method. So I may want an enemy to move up and down on the y axis, but if the player bumps into him I don't want the enemy to go flying off into space because of a y axis offset. A configurable joint is amazing, but does not work to my knowledge, as I can't move the object at all. I was thinking maybe something with Math.clamp, but I'm not sure if that's the best solution. more ▼ asked Feb 09 '10 at 06:01 PM dhendrix 2.2k ● 25 ● 34 ● 59 it would be great if you can edit in and example of your clamp theory. Feb 09 '10 at 09:56 PM Nicolaj Schweitz ♦♦ Well, now that I think about it, that wouldn't work. At certain points I may want the player to "descend" through the level on the y axis, in a on-rails type of way. Clamping movement wouldn't work, as that would limit the amount the player could move.So basically, I want objects to be able to move freely on the y axis, but not move at ALL on that axis in terms of physics or collisions. Feb 09 '10 at 10:29 PM dhendrix add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

 0 You could Make a script which clamps the character to a certain position on the y-Axis. Then, when you actually want to move the character on that axis, do that via the script. Like this: ``` ``````var yPos = 0.0; ``````function FixedUpdate () { ``````transform.position.y = yPos; ``````} ``````function Move (var newPos: Vector3) { ``````transform.position = newPos; yPos = newPos.y; ``````} ``` more ▼ answered Feb 10 '10 at 10:29 AM jonas echterhoff ♦♦ 9.8k ● 7 ● 23 ● 104 That's a simple but effective solution, thanks. Feb 10 '10 at 07:28 PM dhendrix add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

By Email: