- Home /
How can I stop OnMouseDrag from overriding a hinge joint's attachment?
I am trying to create a springboard, where the player will click on an object sitting on the end of the board, pull it down with the mouse and release to launch the object into the air. I created a previous post trying to figure out how to do this with inverse kinematics, but then realized I might be able to achieve this effect with hinge joints. Currently, I have a series of hinge joints attached to several bones in a long board-shaped mesh.
However, there are still a few problems plaguing me. First off, I would like to have the tip of the springboard follow the movement of the object sitting on it. So in other words, if the player clicks on the object and drags it down, it appears as though the object is pushing on the springboard. I have tried making the last bone in the springboard's armature parent the object when it is clicked on, however this causes the hinge joint on the springboard to fight against the OnMouseDrag position as it constantly updates the position causing it to jitter constantly. I would like the motion to be nice and smooth as the player moves the mouse around.
Secondly, pulling the object away from the springboard causes the springboard to stretch. As soon as the object is released, the springboard snaps back into place, but this seems to be a result of the OnMouseDrag position overpowering the constraint of the hinge joint on the armature. Is there a way to tell the hinge joints to stay connected even if the mouse is moved away from the springboard's position?
Hopefully I explained all of this clearly enough. It's kind of a confusing issue unless you see it in action. Thanks in advance for any advice on how to go about this though.
Answer by smoggach · Aug 14, 2014 at 08:23 PM
Hey there. I have an idea of the kind of solution you're looking for. You need a buffer between your mouse drag position and applying force to the springboard. You're not going to get the results you want unless you manipulate your physical objects with physical forces only.
Myself I would have one script with a vector3 to represent where the mouse should be if it was moving smoothely. Then I would use OnMouseDrag to modify that vector3. Then in an Update function I would LERP this Vector3 towards the actual mouse position while applying a constant force to the spring based on the distance between that lerped vector3 and spring's resting position.
It sounds confusing but really the solution is just to have some kind of buffer translating mouse coordinates into the right forces to move your object where you want it.
Your answer
Follow this Question
Related Questions
Is it possible to only allow one direction of rotation using a hinge joint? 2 Answers
Setting Scroll View Width GUILayout 1 Answer
Very odd but harmless error? *Not that urgent* 1 Answer
destroy hinge joint component from another object in javascript 2 Answers
Disabling Rigidbody constraints on GameObject that script is attached to 3 Answers