trajectories


Today i investigated the calculation of trajectories for a simple jump like path that looks like a sin and cos half circle and a cannon ball trajectory that can handle wind.

The jump was no problem to solve. It is just sin applied to x axis and cos applied to y axis by using degrees 0 - 180 step at 5. Then i rendered the trajectory as a point sprites to see how the height multiplied at y axis and length multiplied at x axis changes the trajectory and found the best one that i need for a game.

The cannon ball was a harder task. It is not a sin cos but you could use the jump trajectory to made it simple looking. So for the distance i used an vector calculated from angle. And the resulting dx,dy values are multiplied by speed so you get an move vector. From that point move forward each step until you get to the distance limit. But each step apply gravity to y axis so the ball goes down. And apply wind so it affects only x axis and you will see the standart cannon ball simulation. It is not physics based. And does not use the internet math that i found because it was hard to use and i do not do math like in young days so i rather found a dirty solution.

Trajectory was a class that only stores points calculated by PathJump or PathCannon classes applied as path to the Trajectory class. Thus i get some points and i can use them to shot eveytime or calculate again when some conditions like wind change.

A technique worth for preparation if you want to make some angry birds like games or shoot some cannons at some targets.

Leave a comment

Log in with itch.io to leave a comment.