I’ve tried this script but it only collides with one at a time and clips with others. Thanks
for(int i = 0; i<currentCollisions.Count; i++)
{
if(Physics.ComputePenetration(
myCollider, myCollider.transform.position, myCollider.transform.rotation,
currentCollisions.transform.GetComponent(), currentCollisions_.transform.position, currentCollisions*.transform.rotation,
out var direction, out var distance))
{_
_if(currentCollisions.transform.tag != “Player”)
{*_
draggedObj.transform.position += direction * distance;
}
}
}
This is the 3rd post on the same subject. Please create a single thread and use that. Do not create multiple posts for the exact same thing please.
https://forum.unity.com/threads/how-to-avoid-clipping-while-snapping-between-two-objects-on-runtime-thanks.1343399/
https://forum.unity.com/threads/how-to-avoid-clipping-while-snapping-between-two-objects-on-runtime-thanks.1343300/
I’ll move this post to the Physics forum where it belongs and lock the others.
Here’s how to post code on the forums using code-tags .
Thanks.
1 Like
You cannot make it do something that it isn’t designed to do. This is what the physics solver does, it calculates a solution to all contacts.
Resolving penetration with one thing might cause penetation of another or several things. You have to calculate all the penetrations and work out the best way to solve it. Doing that takes knowledge of such things, something way beyond what I could describe here.
Solving it is therefore much harder than stopping it penetrating in the first place. If you can do that then you don’t have this issue so you’d need to use physics queries to ensure that doesn’t happen.
1 Like
Hello, MelvMay, I’m sorry for that, I’m trying to figure out how to delete the old threads, you’re right I’ve solved the problem by creating a ghost object which checks the collision before the main 3d model follows.
I’ve just deleted them for you.
Glad you got it working. Good luck with it!
1 Like