如何:夹紧推力的影响,同时允许其他力是无限的。
火箭可以向旋转的方向推进。只有爆炸才能把它推过最高速度。我在寻找一种理论而不是代码。
任何帮助都将不胜感激。
解决了
编辑:最高速度由推力速度和摩擦力决定.
推力可以叠加在速度上,但当摩擦大于推力速度时,可以达到最高速度。
vx = (vx + fx) *fr -- velocity = (velocity + force) *friction
vy = (vy + fy) *fr当速度足够高时,附加力将被摩擦力扣除。
fr = .9:很难看到最高速度
fr = .6:很容易看到最高速度
发布于 2016-04-19 07:16:57
控件:左、右和推力
推力的最高速度可以通过摩擦来调节。
-- VARIABLES
player = {
frc = .95, -- friction
acc = .05, -- acceleration
max = .5, -- acceleration max
deg = 0, -- rotation in degree
rad = 0 -- rotation in radian
-- rotation is CW and 0 points to the right
}
-- MAIN UPDATE
function love.update()
control(player)
applyVelocity(player)
end
-- UPDATE
function control(a)
if L then addRotation(a,-5) end
if R then addRotation(a, 5) end
if U then thrustOn(a) else thrustOff(a) end
end
function applyVelocity(a)
-- velocity + force
a.vx = (a.vx + a.fx) *a.fr
a.vy = (a.vy + a.fy) *a.fr
-- position + velocity
a.x = a.x + a.vx
a.y = a.y + a.vy
end
-- OTHER
function thrustOn(a)
accelerate(a)
rotateDist(a)
end
function thrustOff(a)
a.f = 0 -- integer of force is used to convert to point (x,y) with (rad)
a.fx = 0
a.fy = 0
end
function addRotation(a,deg)
a.deg = a.deg + deg
a.rad = math.rad(a.deg) -- math.sin/cos functions use radian instead of degree
end
function accelerate(a)
a.f = a.f + a.acc
if a.f > a.max then a.f = a.max end
end
function rotateDist(a)
-- end point of force rotated from player
a.fx = a.f *math.sin(a.rad)
a.fy = a.f *math.cos(a.rad)
endhttps://stackoverflow.com/questions/36689979
复制相似问题