I think I have to use a Raycast but I’m having some difficulties with it, for some reason it won’t detect any objects except the player? Could you guys give me a sample code
Note: yes I did make a mask for the raycast to detect layer 9 only (my ground/platform layer). I also tried Raycast2D and again to no success.
so you want an enemy to be able to jump from platform A to platform B?
If I’ve got that right then all you’ll need is a raycast to detect when the enemy is on the edge of a platform, if they are then add force to their rigid body.
Something like this:
RaycastHit edgeDetect;
float detectDist;
bool isOnEdge;
void FixedUpdate()
{
if (Physics.Raycast(edgeDet.position, Vector3.down, out edgeDetect, detectDist))
{ isOnEdge = false; }
else { isOnEdge = true; }
if(IsOnEdge) { //Add Force to RigidBody}
else { return; }
}
That code will draw a ray straight down and return “isOnEdge” as false until it is no longer colliding with anything. Put it on an empty gameObject that is a child of your enemy and slightly ahead of it.
Should give you somewhere to start (If I was correct in what you were asking).