# Simple trajectory calculating

Hi,
I’m trying to develop a little sketch that manages the trajectory of balls that fall from the top of the canvas, as shown on this diagram.
I want each ball thrown from the top of the canvas to have a trajectory that points to the middle of the canvas at the bottom, where the stationary player is located. (represented here by a triangle).

Could someone suggest a piece of code that would be suitable?

Num

Lots of possibilities

Look at lerp() command in the reference using start position and target position

Another idea would be to look at atan2 and use the angle with cos and sin

Hi Chrisir,

I couldn’t find a piece of code that meets my needs and that uses the lerp( ) function or other trigonometric functions. But I adapted your idea based on “lerp( )” but using the “map( )” function.

It’s not very elegant nor very precise from the point of view of the real laws of mechanics, but it’s pretty much what I was looking for…

Here’s the snippet of code : https://jsfiddle.net/hfp0me29/2/

(you can click on the canvas to pick more falling particles and see that they converge pretty well toward the bottom center).

1 Like

hi

see this nice game

Game from Japan

Hello everyone,

On my JsFiddle code snippet above, we can see that the farther the ball is dropped from the central axis, the less its fall converges towards the center.

If someone could suggest a small improvement to correct this drawback, I would be interested!