Jump to content

Power impulse


Andrey Zimin
 Share

Recommended Posts

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

Line 38... added elevation variable.

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.  :D

https://www.babylonjs-playground.com/#IFFDYH#7

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

Link to comment
Share on other sites

21 minutes ago, Wingnut said:

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

Line 38... added elevation variable.

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.  :D

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

Link to comment
Share on other sites

ohhhh.  That's harder.  :)

https://www.babylonjs-playground.com/#IFFDYH#8

See lines 52-53... a distance "compensator".  :D  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.

Link to comment
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.

http://www.bbc.co.uk/bitesize/higher/physics/mech_matt/analyse_motion/revision/2/

Link to comment
Share on other sites

19 minutes ago, Wingnut said:

ohhhh.  That's harder.  :)

https://www.babylonjs-playground.com/#IFFDYH#8

See lines 52-53... a distance "compensator".  :D  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

Link to comment
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.

http://www.bbc.co.uk/bitesize/higher/physics/mech_matt/analyse_motion/revision/2/

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

Link to comment
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.

https://www.babylonjs-playground.com/#25OQ8V#13

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!

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...