- Home /
Stop rigidbodies from bouncing
I have a drag script where I drag one rigidbody up against a kinematic rigidbody to position it. The drag script is really a spring joint that follows the mouse. If I drag the rigidbody near the kinematic rigidbody the rigidbody starts vibrating. I've tried adjusting the physics parameters but haven't found any solution to calm the vibrations. I'd like it to just hit the other object and stop, not vibrate. The object that it's running into is kinematic.
Does anyone have any suggestions?
Thanks,
Answer by Muuskii · Jul 27, 2012 at 03:49 PM
Your problem is being cause by the fact that your drag script:
Sets position of the object
It's inside a collider so it gets shoved away
But now it's away from where it's being dragged so it snaps back again
etc, etc
A more physically accurate way of doing this (and this is how most games do it) is to make a "gravity point" where you want the object to be and Addforcing the dragged object towards the gravity point. Make sure to use drag when the object is getting close so it doesn't overshoot.
There are other methods of countering overshooting but that's the most basic. This will let you drag objects around and knock stuff over! :3
Extended functionality:
When you Raycast to find the drag point, you can use Rigidbody.AddForceAtPosition to make sure the pivot point is where the player grabbed it. For instance, if you had a teddy bear and the player had his mouse over it's arm when the dragging started; The bear would rotate as if being dragged by the arm.
Note: If you have a Bear made with some InteractiveCloth You might want to attach a collider to make it move even more realistically.
Answer by Frenchwise · Jun 20, 2015 at 06:09 PM
I encountered a similar problem, which was that when my Player object was hitting a boundary it would fly endlessly away from the kinematic boundary.
A simple fix for me was to add a small amount of 'drag' and 'angular drag' to the rigidbody to stop the infinite movement. You could try setting the drags to 'infinite' also, which would make it stop moving immediately if that's what you're going for.
@Frenchwise bro I owe u my life I was trying to figure this out for ages thank you so much!!!! :DDD
Answer by ScroodgeM · Jul 27, 2012 at 10:05 AM
if both of your objects has colliders, then an object that is not kinematic will be thrown away from the second. it's a physics effect.
if you move an object using mouse, the object should be kinematic rigidbody - that's what for this option is created. once object dropped, make it physics-free rigidbody again.
Your answer
Follow this Question
Related Questions
Help with character controller collision... 2 Answers
physics culling mask? 1 Answer
Do you have to have a rigidbody component for collision detection? 1 Answer
Keep Horizontal Momentum after Jump 2 Answers
Collision.impulse = 0 in OnCollisionStay Kinematic Static collision pair after Update 0 Answers