Well the basic formula for a parabola is: ax^2 + bx + c
And then you have this:
x = v*cos(a)*t
y = v*sin(a)*t - ½gt²
The beauty with using time (t) in the equation is that it makes it easy to determine where your object is at any given moment. You just have to solve for T.
The equations are in my
DB particle tutorial.
Demo
setVirtualResolution(640,480)
obj = createSprite(0)
setSpriteSize(obj, 16, 16)
setSpritePosition(obj, 500, y)
g# = 3.0
v# = 30
angle# = 45
t# = 0.0
baseX = 100
baseY = 300
DO
angle# = 270-atanful(baseX-getrawmousex(), getrawmousey()-baseY)
if getrawmouserightpressed() then v# = v# + 2
if getrawmouseleftpressed() then v# = v# - 2
a_cos# = cos(angle#)
a_sin# = sin(angle#)
// Show initial angle of projectile
drawLine(baseX, baseY, baseX+a_cos#*100, baseY-a_sin#*100,0,255,0)
// Calculate at what time projectile will
// fall back to ground level
// y = v*sin(a)*t - ½gt²
// Draw points along projectile's path
for i = 0 to 20
t# = i
x = baseX + v#*a_cos#*t#
y = baseY - (v#*a_sin#*t# - 0.5*g#*t#^2)
drawLine(x, y, x, y, 255,0,0)
next i
// Ground level
drawLine(0, baseY, 640, baseY,255,255,255)
t1# = t1# + 0.1
x = baseX + v#*a_cos#*t1#
y = baseY - (v#*a_sin#*t1# - 0.5*g#*t1#^2)
setSpritePosition(obj, x, y)
if t1# > 20 then t1# = 0
print("Velocity: "+str(v#))
print("Angle: "+str(angle#))
sync()
LOOP
"You're all wrong. You're all idiots." ~Fluffy Rabbit