How to check for collision between a moving kinematic object and an empty object?

Hello, Unity Community!

I have an elevator (sprite) in my platformer, but I am having trouble making it stop.

I am moving it using this: rigidbody2D.MovePosition(rigidbody2D.position + Vector2.up* Time.deltaTime);, while a variable moving is true;

I have also created an empty game object and attached a collider to it. Now, I have this code here that should detect when my elevator collides with the empty game object, and then make the variable moving false.

void OnCollisionEnter2D(Collision2D coll) {
     if (coll.gameObject.tag == "ElevatorStop")

Now, to clear some questions that might arise: the empty game object has the “ElevatorStop” tag, the layers on which both objects are found can interact, and both objects have “isKinematic=true”.

What am I doing wrong? Or, how would this be achieved with an alternate solution? The solution should be general, because I plan on attaching this script to a prefab.

EDIT: After a bit of tweaking, I noticed that " if (coll.gameObject.tag == "ElevatorStop") " is never true. Ideas?

Why don’t you just animate the elevator to go up? It’s easy and simple for an upward or downward motion

You have to give your empty gameobject a collider. I would give it a boxcollider. You cant detect collision between an empty game object and an object with a collider attached to it.

Two kinematic colliders will never collide.

Setting isKinematic tells the engine “Don’t worry about adding forces to this, I’m going to control it by script”.

Two options to solve

  1. Set isKinematic to false on the elevator stop
  2. Change the collider on elevator stop to a trigger and use OnTriggerXXX