I need help with the “add force” part. What formula should I use in the “angle” or/and “force length” (aka. speed) so the enemy feels intelligent enough?
I’ve not been able to come up with any good ideas.
I might want to give PlatformerObject behavior to the enemy, but I still don’t know how to make it jump towards players position.
Giving the enemy Platformer Character behaviour will simplify things quite a bit.
What you’ll want to do is check if the enemy is on the platform, in which case jump. If the enemy is jumping and the player’s x position is less than the enemy’s x position, move left. If it’s jumping and the player’s x position is greater than the enemy’s x position, move right.
Yes, but this is creates a more simplified result than I wanted. I’ll do this if nothing else works.
I want the enemy to not change direction after it leaves the ground. It can’t influence it’s direction after it is in the air.
Also, I’d like the enemy to vary the jump angle/strength depending on the distance between it and the player. If the player is close, smaller jump is required in order to not jump OVER them.
Then add a variable on the enemy object to indicate which direction it’s jumping. Set this variable when it jumps and check the variable instead of checking its relative position when moving left or right.
As in lower height, or shorter distance? If jump height, then change then change the enemy’s jump speed. If the distance jumped, then modify the maximum horizontal speed when the jumping. Something like:
The abs function takes the absolute value of a number - it removed the negative sign if the numebr is less than 0.
The clamp function will take a number and keep it within the range you give it. In this case, if the number is less than 25 it’ll get set to 25, and if it’s greater than 250 it is set to 250.
If the player is very far away, the enemy does the maximum jump and closes as much distance as it can.
But if the player is very close, the enemy will do a smaller jump in order to avoid jumping over them. A smaller jump in this sense can be achieved both by lowering the jump speed (jump power) or by changing the jump angle towards north (the jump arc of the enemy is higher, but it will move a shorter distance on the x-axis).
I’ll read your message more thoroughly tomorrow and test things out. Thanks for the help.