# Power impulse

## Recommended Posts

Hello, friends!

There is a ball. And on the example, it moves at a constant speed to the desired point.

Q: how do I make a ball move to an arc point? Like a flying projectile!

##### Share on other sites

Hiya AZ!  Here ya go...  https://www.babylonjs-playground.com/#IFFDYH#6

Ling 47... forced direction's Y-component  = elev.

FIRE!     Fun!  A good lookin' start to a new artillery game.

Extra crap:

BJS physics have an "onCollide" event.  Hold that thought.

BJS particleSystems have a .manualEmitCount property (for doing momentary PUFFS of particles).

Particle directions (trajectories) can be told to go sideways-only, from a sphere-shaped emitter like the cannon ball, or from the vector3 of cannonball.getAbsolutePosition().

So... you know... puffs of dirt each time the ball impacts the ground.  Wow!

Believe it or not, just ONE particleSystem can handle ALL ground-impact puffs... even if MANY cannon balls are impacting in many places.

Cool, huh?  *nod*  BJS has SO MUCH FUN available!!!  It makes me over-excited, sometimes.

Added lines 54-63 ... automatic ball recovery when ball falls-off floor.

##### Share on other sites

21 minutes ago, Wingnut said:

Hiya AZ!  Here ya go...  https://www.babylonjs-playground.com/#IFFDYH#6

Ling 47... forced direction's Y-component  = elev.

FIRE!     Fun!  A good lookin' start to a new artillery game.

Extra crap:

BJS physics have an "onCollide" event.  Hold that thought.

BJS particleSystems have a .manualEmitCount property (for doing momentary PUFFS of particles).

Particle directions (trajectories) can be told to go sideways-only, from a sphere-shaped emitter like the cannon ball, or from the vector3 of cannonball.getAbsolutePosition().

So... you know... puffs of dirt each time the ball impacts the ground.  Wow!

Believe it or not, just ONE particleSystem can handle ALL ground-impact puffs... even if MANY cannon balls are impacting in many places.

Cool, huh?  *nod*  BJS has SO MUCH FUN available!!!  It makes me over-excited, sometimes.

Here not all so simply! The fact that you need to hit the ball exactly the place of the click!

##### Share on other sites

ohhhh.  That's harder.

See lines 52-53... a distance "compensator".    A tweaker.

Maybe not so good,  but it is one more playground to play-with.

I click RUN for EACH test-fire... because... I see SOME "residual energy" in the ball, sometimes... when using auto-recovery.  Cause:  unknown.

Also, I adjusted the ball to start perfectly upon-ground.  *shrug*  It is ALMOST accurate.  Bad for SHORT-distance shots, though.

Perhaps you can adjust better, or think-up better idea.  Others may comment soon.

##### Share on other sites

For the ball to hit exactly the place on the ground that was clicked on you need to know the acceleration due to gravity, G,  that is being used in the physics engine. Given the horizontal linear velocity, V, of the ball towards the click point you can calculate the speed of the ball  ||V|| and you can also calculate the horizontal distance, D, between the ball and click point. Then the time, T, to reach the click point will be found from T = D/||V||. So you now need a vertical velocity W such that after a time T the vertical displacement will be 0, this can be found using Newton's equations of motion in this case 0 = WT - 0.5GT*T.

##### Share on other sites

19 minutes ago, Wingnut said:

ohhhh.  That's harder.

See lines 52-53... a distance "compensator".    A tweaker.

Maybe not so good,  but it is one more playground to play-with.

I click RUN for EACH test-fire... because... I see SOME "residual energy" in the ball, sometimes... when using auto-recovery.  Cause:  unknown.

Also, I adjusted the ball to start perfectly upon-ground.  *shrug*  It is ALMOST accurate.  Bad for SHORT-distance shots, though.

Perhaps you can adjust better, or think-up better idea.  Others may comment soon.

I had such a decision, but I thought that could be done somehow by BJS forces

##### Share on other sites

8 minutes ago, JohnK said:

For the ball to hit exactly the place on the ground that was clicked on you need to know the acceleration due to gravity, G,  that is being used in the physics engine. Given the horizontal linear velocity, V, of the ball towards the click point you can calculate the speed of the ball  ||V|| and you can also calculate the horizontal distance, D, between the ball and click point. Then the time, T, to reach the click point will be found from T = D/||V||. So you now need a vertical velocity W such that after a time T the vertical displacement will be 0, this can be found using Newton's equations of motion in this case 0 = WT - 0.5GT*T.

So I knew that I have to remember school :))

##### Share on other sites

Thanks @JohnK

Hey, remember that "thing" that @jerome built?  https://www.babylonjs-playground.com/#PBVEM#161

That thing... phew.  No physics engine, yet ball-bounce parabolas all over heck.  Might be some code to steal... in there.

##### Share on other sites

Oh, hey, I found Jerome's "pucker cannon" that he once made for me.  It tries to pucker-up like a cartoon cannon, and then fire a ball, with parabola and bounce.  FUN!  No physics engine.

In France, I guess "pucker" == "buggle"    Here in the USA where I am, I'm not sure we use the word "buggle" very often, but heck, let's give it a chance.

Let's see... a scary, intense scene in a movie... would be called a "butt-buggler" scene.  heh.  I like it!

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.