Andrey Zimin Posted February 15, 2018 Share Posted February 15, 2018 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! here - https://www.babylonjs-playground.com/#IFFDYH#5 Quote Link to comment Share on other sites More sharing options...
Wingnut Posted February 15, 2018 Share Posted February 15, 2018 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. https://www.babylonjs-playground.com/#IFFDYH#7 Added lines 54-63 ... automatic ball recovery when ball falls-off floor. Quote Link to comment Share on other sites More sharing options...
Andrey Zimin Posted February 15, 2018 Author Share Posted February 15, 2018 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. Here not all so simply! The fact that you need to hit the ball exactly the place of the click! Quote Link to comment Share on other sites More sharing options...
Wingnut Posted February 15, 2018 Share Posted February 15, 2018 ohhhh. That's harder. https://www.babylonjs-playground.com/#IFFDYH#8 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. Andrey Zimin 1 Quote Link to comment Share on other sites More sharing options...
JohnK Posted February 15, 2018 Share Posted February 15, 2018 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/ Andrey Zimin and Wingnut 1 1 Quote Link to comment Share on other sites More sharing options...
Andrey Zimin Posted February 15, 2018 Author Share Posted February 15, 2018 19 minutes ago, Wingnut said: ohhhh. That's harder. https://www.babylonjs-playground.com/#IFFDYH#8 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 Quote Link to comment Share on other sites More sharing options...
Andrey Zimin Posted February 15, 2018 Author Share Posted February 15, 2018 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 :)) Wingnut 1 Quote Link to comment Share on other sites More sharing options...
Wingnut Posted February 15, 2018 Share Posted February 15, 2018 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. Quote Link to comment Share on other sites More sharing options...
Wingnut Posted February 15, 2018 Share Posted February 15, 2018 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! Andrey Zimin 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.