[Fixed] Simple sine/radians problem - I think

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
togFox
Party member
Posts: 384
Joined: Sat Jan 30, 2021 9:46 am

[Fixed] Simple sine/radians problem - I think

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:

Code: Select all

  if love.keyboard.isDown("up") then
Lander.engineOn = true
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.

(actually kinda fun)

LunarLander.zip
Edit: I made a zip file and not a .love file in case anyone thought this was 'production ready'. It's not. Just my own little habits I guess.
Last edited by togFox on Mon Sep 20, 2021 1:27 pm, edited 1 time in total.
MrFariator
Party member
Posts: 282
Joined: Wed Oct 05, 2016 11:53 am

Re: Simple sine/radians problem - I think

It's not really about the radians, but rather this peculiar line at the top of main.lua:

Code: Select all

Lander.speed = love.math.random(0,1)
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.
togFox
Party member
Posts: 384
Joined: Sat Jan 30, 2021 9:46 am

Re: Simple sine/radians problem - I think

hmm. Interesting. I didn't see that line. I guess the intention was to spawn the lander with a random velocity to force an immediate reaction.

I shall review and fix. Thanks.
pgimeno
Party member
Posts: 2819
Joined: Sun Oct 18, 2015 2:58 pm

Re: [Fixed] Simple sine/radians problem - I think

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.
darkfrei
Party member
Posts: 417
Joined: Sat Feb 08, 2020 11:09 pm

Re: [Fixed] Simple sine/radians problem - I think

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).
Falling in LÖVE
I Löve Lua and Love2D
togFox
Party member
Posts: 384
Joined: Sat Jan 30, 2021 9:46 am

Re: [Fixed] Simple sine/radians problem - I think

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.

Who is online

Users browsing this forum: No registered users and 35 guests