# Angry Birds style path prediction

**URL:** <https://forum.babylonjs.com/t/angry-birds-style-path-prediction/6372>\
**Category:** Questions\
**Created:** [October 15, 2019, 12:14am UTC](https://forum.babylonjs.com/t/angry-birds-style-path-prediction/6372 "2019-10-15T00:14:44Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![tkmoney](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/tkmoney/32/4643_2.png) [@tkmoney](https://forum.babylonjs.com/u/tkmoney)\
**Post date:** [October 15, 2019, 12:14am UTC](https://forum.babylonjs.com/t/angry-birds-style-path-prediction/6372/1 "2019-10-15T00:14:44Z")

</div>

Hello there,

Im working on a angry birds clone but in 3d. Im going to be using physics of course but Im wondering how I can draw that arc line that shows where the projectile will go.

![Screenshot_9](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/a/a0035f3d0de3583c6e316013685215bbf363a1ec.png)

I know how to render the line with “BABYLON.Mesh.CreateLines” with a spline but Im not sure how I can get the data to create the spline.

Has anyone done something like this already? Thanks!

---

<div class="post-metadata">

**Author:** ![jerome](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jerome/32/22_2.png) [@jerome](https://forum.babylonjs.com/u/jerome)\
**Post date:** [October 15, 2019, 6:07am UTC](https://forum.babylonjs.com/t/angry-birds-style-path-prediction/6372/3 "2019-10-15T06:07:43Z")

</div>

[https://doc.babylonjs.com/how\_to/how\_to\_use\_curve3](https://doc.babylonjs.com/how_to/how_to_use_curve3)

and I think that a good tool to render it would also be the Points Cloud System [Points Cloud Particle System - Babylon.js Documentation](https://doc.babylonjs.com/how_to/point_cloud_particles)

---

<div class="post-metadata">

**Author:** ![JohnK](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/johnk/32/26764_2.png) [@JohnK](https://forum.babylonjs.com/u/JohnK)\
**Post date:** [October 15, 2019, 8:28am UTC](https://forum.babylonjs.com/t/angry-birds-style-path-prediction/6372/4 "2019-10-15T08:28:08Z")

</div>

> [@tkmoney](#):
>
> how I can get the data to create the spline.

You need some maths. The path is that of a projectile, ie a parabola. To get the path you need the initial velocity,` v`, in units per second, of the bird and the angle of projection, `a`. Then `t` seconds after release the horizontal distance traveled is `vtcos(a)` and the vertical distance is `vtsin(a) - 0.5 * g * t * t` where g is the gravity in units per sec per sec

---

<div class="post-metadata">

**Author:** ![nasimiasl](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/nasimiasl/32/34_2.png) [@nasimiasl](https://forum.babylonjs.com/u/nasimiasl)\
**Post date:** [October 15, 2019, 8:46am UTC](https://forum.babylonjs.com/t/angry-birds-style-path-prediction/6372/5 "2019-10-15T08:46:35Z")

</div>

hey  
[https://www.babylonjs-playground.com/#4AEW8L#5](https://www.babylonjs-playground.com/#4AEW8L#5)

i make this sample to you

**function ball(size,speed,speed\_time, a,sphere )**

size : ball size  
speed : {x,y,z} first power vertical  
speed\_time: how much you need male it reality  
a : gravity vertical;  
sphere : if you make your mesh set it here else that automatically created

for 300 ball [https://www.babylonjs-playground.com/#4AEW8L#6](https://www.babylonjs-playground.com/#4AEW8L#6)

![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/1/1dea5497e3f3e36a1c66e416dc23d07be07d1885.png)

[https://www.babylonjs-playground.com/#4AEW8L#12](https://www.babylonjs-playground.com/#4AEW8L#12)

version 11 : test for 300 balls

---

<div class="post-metadata">

**Author:** ![tkmoney](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/tkmoney/32/4643_2.png) [@tkmoney](https://forum.babylonjs.com/u/tkmoney)\
**Post date:** [October 15, 2019, 6:15pm UTC](https://forum.babylonjs.com/t/angry-birds-style-path-prediction/6372/6 "2019-10-15T18:15:47Z")

</div>

hey @nasimiasl,

Thats cool thx! I realized that I remembered angry birds incorrectly or I was thinking of a different game. Angry Birds has a trail behind the projectile. I think that is really useful for gameplay. I also thought that it gave you a preview path of where the ball was going to go with an arc path. So you would pull back on the slingshot and you would see a dotted line of the arc that the ball would take if you let go. Can I calculate this with the potential velocity, the current angle and the mass of the projectile?

---

<div class="post-metadata">

**Author:** ![Drigax](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/drigax/32/16585_2.png) [@Drigax](https://forum.babylonjs.com/u/Drigax)\
**Post date:** [October 15, 2019, 10:04pm UTC](https://forum.babylonjs.com/t/angry-birds-style-path-prediction/6372/7 "2019-10-15T22:04:03Z")

</div>

@tkmoney Yes you can!

your slingshot pull direction should give you a calculatable initial velocity for your projectile, then its position at any given time t would be:  
p(t) = p0 + v_t + 1/2a_t^2

where p0 is your initial position, v is your starting velocity, and a is your gravitational acceleration [0,-9.81,0] (you can also add any sort of drag effect to this as well).

This is assuming you’re using a real physics model, but the key would be to calculate p(0), p(maxHeightTime), and p(hitsGroundTime) and draw a quadratic path that passes through these points.

---

<div class="post-metadata">

**Author:** ![tkmoney](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/tkmoney/32/4643_2.png) [@tkmoney](https://forum.babylonjs.com/u/tkmoney)\
**Post date:** [October 16, 2019, 12:04am UTC](https://forum.babylonjs.com/t/angry-birds-style-path-prediction/6372/8 "2019-10-16T00:04:20Z")

</div>

Hey @Drigax,

Thanks! I think I understand the gist of what your saying. I wish I had better math skills I would probably be able to fully grok this lol. Is it possible to create a PG to clarify? If not I understand. Thanks!

---

<div class="post-metadata">

**Author:** ![Drigax](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/drigax/32/16585_2.png) [@Drigax](https://forum.babylonjs.com/u/Drigax)\
**Post date:** [October 16, 2019, 6:13pm UTC](https://forum.babylonjs.com/t/angry-birds-style-path-prediction/6372/9 "2019-10-16T18:13:28Z")

</div>

Sure, I’ll put together a playground in the next few days to show you what I mean. I need to learn a bit more about the babylonian way to handle a click + drag + release event with constant updating of the mouse position
