[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
Before you make a thread asking for help, read this.
Post Reply
User avatar
togFox
Party member
Posts: 770
Joined: Sat Jan 30, 2021 9:46 am
Location: Brisbane, Oztralia

[Fixed] Simple sine/radians problem - I think

Post by togFox »

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 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.

(actually kinda fun)


LunarLander.zip
(2.05 KiB) Downloaded 101 times
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.
Current project:
https://togfox.itch.io/backyard-gridiron-manager
American football manager/sim game - build and manage a roster and win season after season
MrFariator
Party member
Posts: 509
Joined: Wed Oct 05, 2016 11:53 am

Re: Simple sine/radians problem - I think

Post by MrFariator »

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.
User avatar
togFox
Party member
Posts: 770
Joined: Sat Jan 30, 2021 9:46 am
Location: Brisbane, Oztralia

Re: Simple sine/radians problem - I think

Post by togFox »

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.
Current project:
https://togfox.itch.io/backyard-gridiron-manager
American football manager/sim game - build and manage a roster and win season after season
User avatar
pgimeno
Party member
Posts: 3544
Joined: Sun Oct 18, 2015 2:58 pm

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

Post by pgimeno »

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

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

Post by darkfrei »

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).
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
User avatar
togFox
Party member
Posts: 770
Joined: Sat Jan 30, 2021 9:46 am
Location: Brisbane, Oztralia

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

Post by togFox »

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.
Current project:
https://togfox.itch.io/backyard-gridiron-manager
American football manager/sim game - build and manage a roster and win season after season
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 49 guests