Create enemy that jump to your position

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Edgar Vakhitov

I want to create enemy that just to Player position. It should be simular to enemies from Ori. https://youtu.be/Wh6gBjfXKxw?t=679 . What is the posible ways to implement this. RigidBody or Kinematic. I don’t need exect code but explanation witch approach to choose for implementing this.

:bust_in_silhouette: Reply From: DaddyMonster

Wow, Ori is such a pretty game. Such respect to the devs.

This bit at least is easily done. So, you need some kind of enemy AI to decide when they are going to leap. I’ll put that aside as a separate topic but really it could be as simple as setting a timer with a random value or distance triggering it. AI doesn’t always need to be complicated, it’s just agency.

Ok, so let’s say you’ve got a _timeout() method which has just fired meaning your enemy should jump where the player is at that moment. So, you need a reference to the player. So, maybe when the enemy first spawns it loads the player object as a member variable. I’m going to assume you know how to do that. If not, just ask.

So, now in the firing function we can just grab player.position and we’ve got self.position, the enemy that is. Ok, now there are roughly six hundred and thirty two ways to do the jumping…

Let’s say we decide to use a Tween and the enemy is a kinematic body. So, we cover the x and y moving the enemy up and down. A cubic interpolation, ease in and out, would work really well. There are loads of tutorials on YT on Tween and the docs cover it nicely.

Like I say, this is one solution out of countless possibilities but my guess is it’s what Ori did. I’m not certain though but it would certainly work even if they used a different tactic.

If you put together a project, have a stab at the code and it doesn’t work. Feel free to ask here and post your code.