I got this off a random 2 year old github and found a bug almost instantly. A tiny 100 line file is attached. This is the old lunar lander 'game' but this one line seems to bug out:
if love.keyboard.isDown("up") then
Lander.engineOn = true
local angle_radian = math.rad(Lander.angle)
local force_x = math.cos(angle_radian) * (Lander.speed * dt)
local force_y = math.sin(angle_radian) * (Lander.speed * dt)
-- this will sometimes be zero meaning zero force meaning the lander never slows down
print(force_y)
--
Lander.vx = Lander.vx + force_x
Lander.vy = Lander.vy + force_y
else
Lander.engineOn = false
end
I think, with my basic knowledge - a certain combination of radian + sine will = zero and the ship can't break and can't land properly.
Use UP key for thrust and left/right key to rotate.
For whatever reason, the lander's speed is set randomly at startup, and if love.math.random is used this way it will return only either 0 or 1 (as per wiki). As such, sometimes you can move the ship, sometimes you can't, because multiplying by zero is zero.
pgimeno wrote: ↑Mon Sep 20, 2021 1:31 pm
That's more like engine power anyway, not speed, since it applies to the force. Naming the variables appropriately can protect you from some bugs.
It can be something like specific impulse, that is like-a-speed and has unit as m/s (or just in seconds in other notation).
I've already converted some variable names from French to English. It clearly has bugs and is not finished. That said - beggars can't be choosers and it has given me a head start.