- Home /
Collision detection from specific directions using rigid body character?
I'm building a 2D platformer using a rigidbody character, and I'm having issues with collision.
I had been using triggers that are children to the character to tell if there was a wall to whatever side of the character, but I ran into problems when hitting walls from different angles.
In other engines/tools such as Flash and Torque, you can look to see if your character would be colliding with an object if it was +1 (or -1 or any other value) in a specific direction. I feel like that would be perfect for this, but I can't figure out how to do it in Unity.
I have seen similar questions answered with links to documentation on contact points, but the contact points seem to detect exactly where in the actual world the contact takes place. I don't see how that would help in this case, but if there is a way to detect the relative distance of a contact point from my character that would probably work.
To make things more complicated, the entire game world is composed of "blocks" that you can hit from 4 different sides. Therefore, I don't think having separate "wall" and "floor" objects is ideal. Even if they are simply different colliders within one object, I can see complications coming up (what happens with corners, for example).
Raycasting does not seem ideal since I'd like to be able to detect collision across each entire side of my character (or very close to it), but I am open to raycasting suggestions.
Just now I tried setting it so that the triggers around my character (there are 8, 2 on each side) determine direction only and collision is handled between the character and other objects normally (using onCollision functions). This seems better than what I had before, but some quick testing has revealed that it still is far from perfect.
I can provide code if needed, but I suspect I will need to completely overhaul how I'm doing this. I am using C#.
At this moment I forget exactly why I decide to use a rigidbody instead of the built in character controller, but I think it was a combination of being able to do what I wanted with physics and the fact that it felt simpler to me at the time.
Any help or insight would be greatly appreciated.
Your answer
Follow this Question
Related Questions
How to detect collision on only one side of an object? [C#] 4 Answers
Objects with colliders going through walls and each other. 3 Answers
Prevent a specific RB to influence another, but still collide with everything 0 Answers
Force a script generated primitive to test for collision 2 Answers
Collision problem 4 Answers