Top Down. Enemy Jump

Hello, colleagues! I’m making a game in top down style.

Made an enemy. He has to jump towards the player, jumping over the player’s position. The spider must not stop after reaching the player’s position.

In my code, the spider stops when it reaches a position. How to fix it?

It stops because the you’re only adding a force to move it to the player’s position, so of course once it reaches the player’s X and Y it will just stay there. So it depends, do you want the spider to keep going until it goes off screen or do you want the spider to jump over the player and then stop when it is some distance away from the player?

Also is there a reason you’re storing the player coordinates in scene variables and then referencing those variables for the move action? Why not just access the coordinates directly?

I want the spider to jump over and stop at a distance from the player.

I use a variable so that the spider does not chase the player, but jumps over the position where the player was.

What do the characters look like? Is it overhead or is it side-view with top-down for the movement? I’m asking bc I’m wondering how you’re handling the spider’s jump. If it’s overhead the spider would take a straight path. Maybe scale it’s size up a little as it goes over the player. You could create a little formula based on the distance between it and the player. If it’s more of a side-view then the spider could make an arch or curve like movement to make it look like it’s jumping.

Either way, the jump could be based on the distance from the player. If the spider can jump 200 px then when it’s 100 px away from the player then it would jump 200 px. Maybe before and after it’s movement is sort of ramdom like. So, it kind of scurries around. Maybe, you could use a tween for the jump.

If the player is 100 pixels away, then the spider jumps 200 pixels. That’s how I want it. So that the spider jumps in the direction where the player is.

An arch over the player would look good. Although, I’m currently unsure of how to do it. It would have to be based in the angle bc if it was directly over or under the it would be a straight line. It could be something luke following a curve. You know the start, the end can be calculated and the control point could be somewhere above the player.

It could be sort of like this project. The slider could be replaced by a variable tween. Just a thought. It’s up to you. It’s your project. I could test it later when I’m at my PC.

Unfortunately, I don’t understand what you’re talking about ((( I just want the spider not to stop, so that it stops when I want it to. So that it stops on a timer. So the spider flies for 1 second, after which it stops

In that case, maybe change the immediate force to permanent. And then the timer with the stop action could stop it. On the event that starts the timer you could add a permanent force and when the timer is greater than some amount you could stop it or switch it to a random like movement. You would only need the one timer event if you apply the force toward player when the timer was started.

1 Like

Thanks! I didn’t think about it

1 Like