- Home /
Collide only on top and pass through the other sides
I have a gameobject with rigidbody and collider (sphere for now)
And I have a platform with rigidbody and collider (mesh)
I don't want the 1st gameobject to collide while it passes through from the bottom side but collide only when it lands from the up side.
Any clues?
Answer by Loius · Nov 29, 2012 at 11:47 PM
Objects can only collide with 'outward-facing' polygons (the face normal has to point towards the incoming object). So objects can always pass through planes from one side, but not the other (assuming the plane's two triangles aren't facing opposite directions).
I'd recommend making a non-collider object for the visual part of the "platform", and use a simple plane collider (or a box collider with no bottom panel) for collision - easy to build in a 3D modeling program, just bring in the default cube object and get rid of the faces you don't want.
(you'll need to use the Mesh Collider to use custom meshes for collision)
yes but while it passes through the platform, my OnCollisionEnter event will trigger, right? I want to trigger it only when co$$anonymous$$g from up with direction down.
It won't trigger OnCollide unless it actually collides - which means it hits the thing and is affected by physics.
Yes, I know. But I don't want to collide when it comes from bottom and passes through it. I just want when an object lands onto the collider, from top with direction to bottom ( -Y ).
Answer by sunweixiao · Nov 10, 2016 at 08:12 AM
A Plane has 2 faces,the front face and the back face. If you attach a collider to this plane.The front face can detect collide and the back face can't. You can rotate your plane for 180 degrees.
Answer by BiG · Nov 29, 2012 at 10:28 PM
Does this help?
http://answers.unity3d.com/questions/240824/detect-collision-with-the-side-of-an-object.html
Thanks for the reply. But that doesn't solve the problem to pass through from the bottom side and collide only when landing on top. I have it like that up to now(2 colliders), when I collide on the bottom collider it deactivates the top and when i exit it activates again. But I was looking for something more efficient.
Answer by Bunny83 · Nov 30, 2012 at 12:00 AM
I've written a little script which can remove faces from a mesh at runtime based on the normal angle:
http://answers.unity3d.com/questions/236313/one-way-collider.html
Answer by ozdenmurat · Sep 19, 2020 at 04:55 PM
You can add to your player two different colliders in different places, forexample like this; capsule collider for head, box collider for legs.
public class Player : MonoBehaviour
{
Rigidbody2D rb;
CapsuleCollider2D myhead;
BoxCollider2D myfeet;
void Start()
{
rb = GetComponent<Rigidbody2D>();
mycollider = GetComponent<CapsuleCollider2D>();
myfeet = GetComponent<BoxCollider2D>();
}
Then you can use colliders for different purpose ;
private void Jump()
{
if (myfeet.IsTouchingLayers(LayerMask.GetMask("Foreground")))
{
if (CrossPlatformInputManager.GetButtonDown("Jump"))
{
//rb.AddForce(Vector2.up * jumpSpeed);
rb.velocity += Vector2.up * jumpSpeed;
}
}
i hope this will help you.
Your answer
Follow this Question
Related Questions
Raycast collision detection? 1 Answer
OnTriggerEnter2D not triggering 2 Answers
ControllerColliderHit, two objects, takes wrong one 1 Answer
Change Direction on Collision 6 Answers
detect power of a hit for VR boxing 0 Answers