- Home /
How to limit the motion direction of a GameObject?
As you can see in following example and picture, I want to build a mechanism which converts a rotation of a GameObject to a motion on a straight line of another GameObject. The whole mechanism should be based on Physics components. Therefore, I add two hinge joints on the red fastener. Their rotation axis is positioned at the drilling whole at the bottom and top of red fastener. But now, my problem is to limit the motion the yellow slider on top of model. It should only be moving in the direction like slider is mounted. The problem is, that I can not see a way to define the allowed movement direction. Because I can not use the constraints of the ridigbody components, and I also don't want to use colliders or a script.
Is there any better idea how I can constrain the movement only with physics components?
Answer by ahsen35813 · Apr 01, 2020 at 03:57 PM
If you click on the yellow box which you want to constrain, if you add a rigidbody component you will be able to constrain rotation and motion in certain axes. So if you add a rigidbody to the yellow slider and then constrain x, y, and z rotation and then constrain x and z motion, the only direction the slider should be allowed to move would be up and down, and it wouldn't be able to rotate either. I have tested this, and it defenitely works.
EDIT: Sorry, I didn't see that you did not want to use Rigidbody components. However, I read somewhere in the Unity Documentation a while ago that it's best for moving objects to have a Rigidbody component.
@alsen35813 I already tried it by using the ridigbody constraint. This way is only working, when the slider is in an upright position but here, the slider is positioned with an angle as you can see in the picture. Therefore, constraining the ridigbody isn't sufficient to restrict the movement direction. Do you have another idea?
Oh I see. I'm sorry about that. I'm not sure how I would do that either... $$anonymous$$aybe if there is nothing else in the scene besides the above components and gravity is turned off, then you can rotate everything in the scene, including the camera?
Your answer
Follow this Question
Related Questions
Creating draggable hinge joint 1 Answer
How may I observe expected physical interactions while using Rigidbody.MoveRotation()? 1 Answer
Camera and mesh not colliding 1 Answer
What is the most accurate method of calculating total rotations of a rigidbody? 1 Answer
drag object including free rotation 0 Answers