- Home /
How to stop Kinematic Rigidbody from moving through walls
Hey,
I have a rigidbody that is being dragged around based off a touch input via rigidbody.movePosition. Currently, the user can drag the object through surrounding geometry such as walls. How can I stop the object from passing through the environment geometry? It happens because the object can be moved quickly. I changed detection to continuous dynamic, but it didn't help.
I have tried to use Physics.CheckSphere to see if any surrounding colliders i.e. my environment are touching the sphere. However, this always returns true. The docs are unclear as to if the checkSphere includes the collider attached the the draggable object.
I've also tried to use a Physics.Raycast to see if a collider is in front of the object based off a very small distance. This seemed to work in that I could tell I was about to hit something, but from there I wasn't sure how to stop the object from passing through the environment.
I'd greatly appreciate any advice!
Thanks,
Wes
hi wes, I'm assu$$anonymous$$g that colliders are attached to your walls, yes? Is the 'is$$anonymous$$inematic' flag on your wall and rigidbody colliders turned off (unchecked)?
Hi Dendro. Yes, I have colliders on the walls and is$$anonymous$$inematic is turned off. I think it has to do with the speed of rigidbody as if I slowly drag the RB, it collides correctly. I also changed collision to continuous dynamic as this is supposed to account for high speed collisions, but it's not working either.
Answer by The 3D Ninja · Dec 09, 2010 at 05:03 PM
I have a solution and I wanted to share it. I determined that the issue was the rigidbody was moving too quickly. I tried setting the collision detection to Continuous Dynamic, which can account for quick collisions, but this didn't work.
My solution was to apply a dampening to the drag of the rigidbody so that it was inherently slower than the finger movement. To do this, I used Vector3.SmoothDamp, which worked perfectly.
Could you please post some code examples?
TIA, R.
Answer by joshuapeacock · Jun 11, 2018 at 06:42 PM
The accepted answer does not work in my situation I need precise movement control. But I have the same situation where I am moving a rigidbody with swipe input and on mobile device with movePosition. I cannot find a solution anywhere to provide continuous collision detection when use movePosition.
Your answer
Follow this Question
Related Questions
Drag a rigidbody2D around scene 2 Answers
Child Rigid Body collision problem 2 Answers
Make isKinematic false when touching a Collider? 1 Answer
[SOLVED] Desactivate pushing forces between two objects 2 Answers
CPU cost of using multiple rigidbodies 0 Answers