# Looking for a tutorial.

0 favourites
• 20 posts
From the Asset Store
Carousel Animation, make carousel of you image gallery or anything
• Hi guys,

I am making an enemy that shoots balls in an arch towards the player. I remember reading a tutorial in here with the perfect trajectory curve for the ball to hit the player.

Can you guys remember who posted the tutorial?

Thanks! Mikkel :)

• It is available on the start page of editor.

• I have had no luck finding that. Can you be more specific on were to find it?

• Otherwise, check the How do I FAQ for Construct 2 and look for the keyword "archery" and/or "trajectory" to see examples of implementation.

• 1. Go to the editor

2. Select beginner examples

3. There are two examples :- turret behaviour and turret predictive aim

• No Sorry, that is direct fire. I need a trajectory arch for a platformer. But thanks anyway. :)

• ## Try Construct 3

Develop games in your browser. Powerful, performant & highly capable.

Construct 3 users don't see these ads
• Bullet behavior has gravity, just use that.

• I will keep looking then. I know the tutorial is out there. And I might think the Ace rojohound had a part in it. ;)

• Sorry, I just saw you want to perfectly calculate the trajectory to hit the player.

Yea that's gonna need some math. nooooooooooo..

Im sure there was a few examples available over the years. is nOthing coming up when you search? (make sure to search the C2 threads as well) . Or there is probably tons of demos on you tube where you could just transfer over the maths into c3 events. I might have a go on the weekend if I have time.

• I used to know the maths, been awhile since I've studied kinematics but I can probably guess most of it.

If I'm visualising the arc correctly you have 2 variables ( angle and initial velocity ) as well as the position of the player ( which is technically constant in this situation ). As there are 2 variables you end up with effectively infinite combinations, so it can't be solved easily. If you pick an arbitrary value for the angle ( say 45 degrees ) and just vary the power there should only be 1 solution, so we can solve it.

I tried to work out a way to do it if the player is on a different height to the enemy, but couldn't figure it out ( guess I'm a bit rusty ).

Consider vertical movement to the top of the arc ( where the vertical velocity will be 0 and acceleration will be negative g )

``````0 = u + ( -g ) * t
u = g * t
t = u / g
``````

We also know that as there is no air resistance that no horizontal declaration occurs, hence when considering the distance travelled initial and final velocity are the same

``````s = u * t
``````

As the angle is 45 degrees the initial horizontal and vertical velocity are the same. The arc is symmetrical so we know that t to the top of the arc is exactly half the total time. So let's combine the equations.

``````s = u * (2 * (u / g))
s = 3 * u / g
s * g = 3 * u
u = (s * g) / 3
``````

Little g is a constant, and we can calculate the horizontal displacement trivially so you can figure out the initial velocity quite easily. I'm not sure how your actually simulating this, so you might have to fudge the math a little to match up. Changing the target elevation relative to start break the symmetry of the arc, which makes things more complicated to work out.

I think my math is right, but it's untested and I haven't done much like this for around a decade

• Sometimes I surprise myself. Try this. Just make a Cannon sprite (with an image point 1 at the end of the barrel), a Bullet sprite with bullet behavior and a Badman enemy sprite with drag and drop behaviour. Works perfectly and really cool. bullets allays hit the badman as long as in range. sorry I cant upload anything as Im at work. I just copied the formula off Wikipedia

``````| Global number RangeX‎ = 0
| Global number AltitudeY‎ = 0
| Global number GravityG‎ = 5000
| Global number BulletVelocityV‎ = 3000
| Global number TanAngleA‎ = 0
| Global number AngleA‎ = 0

+ System: Every tick
-> System: Set RangeX to Badman.X-Cannon.X
-> System: Set AltitudeY to Cannon.Y-Badman.Y
-> System: Set TanAngleA to ((BulletVelocityV^2)+((√((BulletVelocityV^4)-(GravityG×((GravityG×(RangeX^2))+(2×AltitudeY×(BulletVelocityV^2))))))))÷(GravityG×RangeX)
-> System: Set AngleA to atan(TanAngleA)

+ System: Every 0.3 seconds
-> Cannon: Spawn Bullet on layer 0 (image point 1)
-> Bullet: Set Bullet gravity to GravityG
-> Bullet: Set Bullet speed to BulletVelocityV

+ System: Every tick
-> Cannon: Set angle to -AngleA degrees``````
• Nepeo NetOne - hehe, you might actually have triggered me to take up math again, and that is an achievement itself guys. :D I did not recall all these factors and it might have been a somewhat more simple tutorial. But I will certainly dig into it and show you what it ended up like. Much much appreciated and cheers guys! :0)

• this is a thread from 3 years ago that talks about how to aim like Angry Birds. Down near the bottom there is a post from me with some links to samples I made the year before. (the math in there was derived from earlier posts from ROJOhound).

I think the one that uses Chipmunk physics is slightly better, but requires the chipmunk physics plugin... the regular physics one should also help...

https://www.construct.net/en/forum/construct-2/how-do-i-18/apply-gravity-concept-angry-113751?kws=angry%2bbirds

• basically same formula as above

note there are allways 2 solutions for a given velocity as it is a squareroot. one is high and one is low, Ive randomly chosen one or the other here.

• Arh mann, thank you NetOne! That is just as great as it could be. I owe you one m8. :)

• 20 posts