[SOLVED] nemies throw rocks at player, trying to get consistent-ish rock arc

Bentley

Member
I'm goofing around with a Pooyan remake:

Enemies float down on a balloon and you move vertically in an elevator. As the enemies descend, if their y is roughly equal to your y, they throw a rock at you.

When I watch the gameplay, the rock seems to get a consistent arc, even though enemies are at varying x distances away.

I tried a bunch of crap. I tried angling the throw higher the further the enemy is away. I tried setting a target_y above the player's head and having gravity kick in at a certain point. But I can't get the trajectory to look right.

How would you approach this? I keep swimming in the same pool of my own bad ideas, so other ideas are much appreciated. Thanks for reading.
 
Last edited:
G

Guitarmike

Guest
I would google "projectile motion." There are formulae you can use to create an arc that will land on/near the player while accounting for varying distances between the enemy and player. Look at lengthdir_x, lengthdir_y, point_distance, and point_direction, which should also be helpful.
 

Tsa05

Member
I started typing out an answer, and then realized there's got to be someone explaining this better with videos, graphs, and illustrations.

https://www.khanacademy.org/science...launching-and-landing-on-different-elevations

Basically, an intercept script creates the "launching and landing on different elevations" scenario. Computing the interception angle provides you with a way to draw a straight line from where the projectile is *now* to where the target should be when the projectile lands. Thus, you've got the starting point and ending point, at 2 elevations. That's where the link above takes over.
 
Top