let's ignore the deltatime dt stuff for a moment and also only deal with speed in x-coordinate.
every physic frame the position changes by a certain amount. This difference between old and new position is called speed.
also known as:
What happens if xspeed is not constant, but also changes every time? The difference between old and new speed is called acceleration.
also known as:
example:
Code: Select all
local x,y,xspeed,xacc = 0,0,0,0,0,0
local traces={}
function shoot()
x=0
y=40
xspeed=0
xacc=200
xspeedmax=1000
traces = {}
end
function love.load()
shoot()
end
local t = 0
function love.update(dt)
x=x+(xspeed*dt)
xspeed=xspeed+(xacc*dt)
if xspeed>xspeedmax then xspeed=xspeedmax end
---
if x > 800 then y = y + 50 x=0 end
if y > 400 then shoot () end
t=t+dt
if t > 0.1 then traces[#traces+1] = {x=x,y=y} t=0 end
end
function love.draw()
love.graphics.circle("fill",x, y, 20)
love.graphics.print("xspeed:"..xspeed, 100, 300)
for i,v in ipairs(traces) do
love.graphics.circle("line",traces[i].x, traces[i].y, 20)
end
end
1) Try different values in shoot() function.
2) Try setting a high startspeed and negative acceleration.
3) Now what really moves the hamsterball is when the acceleration also changes. The difference between old acceleration and new acceleration is called jerk.
also known as:
Code: Select all
xacc=xacc+xjerk
xspeed=xspeed+xacc
x=x+xspeed