- Home /
Avoid physics from collision
This is hard to explain, but here goes.
I have two different colliders, let's call them playercollider and rockcollider.
Let's say rockcollider is at a specific position, but in one single frame, playercollider spawns in the same position.
What I want to happen: playercollider spawns at the position given, and disables rockcollider's renderer & collider. So it seems the rockcollider is destroyed. I basically want my playercollider to be a bulldozer, that can't be pushed around.
What actually happens: The playercollider is "pushed" outside of the rockcollider, and then it does the job by disabling components.
So what do I need to be aware of? I've tried tons of stuff. Adding physics material with 0 bounciness, toggling/untoggling isKinematic, etc.
If you've read this and still don't know what my problem really is, please say so - and I will edit this question.
And btw. this is a 2d game.
And no, I can't just disable rockcollider first, and then spawn the playercollider. For reasons that isn't important :)
They need to detect first that they are in same position, and then explode the rockcollider.
Answer by CostelloNicho · Sep 03, 2015 at 09:16 PM
How about just checking if the players "to be" spawn location is within the rocks collider.bounds?
For more precision you can take the closest point within the rock to the player's to be spawn position:
RockCollider.bounds.ClosestPoint(playerPosition)
Then check to see if the distance between that point and the player is greater than half the width of the players collider.
Thanks for the answer. I'll see if the contain method will do the job.
I did something else, but your idea inspired me, so I'll give you the points.
Basically I placed a third boxcollider first, destroying the rock. And then spawning the playercollider 0.02 seconds after.
Your answer
Follow this Question
Related Questions
Slow down object about to collide 1 Answer
character bumps when going between overlapping or side by side colliders 0 Answers
Physics2D.IgnoreCollision not working! 0 Answers
Recalculating collisions after Physics2D.IgnoreLayerCollision()? 1 Answer
OnCollisionEnter,OnTriggerEnter making profiler spike 1 Answer