-1

I am making a delivery game and temporarily designed my game so that the player who is a cylinder at the moment has to locate the delivery location which is a flat plane and move onto it in order to deliver the objects.

I have tried adding a 2d box collider to the plane to detect when the player collides with the plane but the collider only works on the x,y axis and i am not able to rotate it 90 degrees.

So my question is what is the best way to determine when the player has moved above the plane?

Here is a picture to demonstrate what i mean:

Before moving onto plane

How to i detect this:

Player is on top of plane

derHugo
  • 83,094
  • 9
  • 75
  • 115
MIM
  • 5
  • 4
  • Have a **trigger** `BoxCollider` in the area above the plane? You will need a 3D collider to interact with the 3D physics engine! 2D and 3D physics in Unity are two completely independent separate engines! – derHugo Feb 21 '22 at 16:18
  • If all else fails, consider periodically casting a ray straight down and checking if it hits the expected surface. Though this is probably rather expensive on the CPU – byxor Feb 21 '22 at 16:20
  • I have that but it doesn't work, When the cylinder collides with the collider noting happens – MIM Feb 21 '22 at 16:26
  • Never-mind I got it to work, i was using onCollisionEnter instead of OnTriggerEnter. Thanks for helping – MIM Feb 21 '22 at 16:31

1 Answers1

0

First, make sure at least one of the objects has a rigid-body component. If you are using a character controller to control your player, add the rigid body to the plane. If you don't want the rigid body to affect the plane, just freeze all the position and rotation constraints. Next, make sure both of the objects have a 3D collider, not 2D. Your game is 3D and needs 3D colliders. 2D is for 2D games such as sprites. (I recommend a cylinder collider for the player and a box collider for the plane.) Make sure the plane's collider "isTrigger" is enabled. This should work for you to detect the collision.