Log In  

How does the sin() function work in pico-8?
I've tried experimenting with it, but it doesn't seem to work the way I want it to.

cls()
print(sin(90)) -- returns 0

I really don't understand, why doesn't it return 1?

P#99863 2021-11-09 13:23

1

There's a section of the manual that describes some of the quirks you're encountering (https://www.lexaloffle.com/dl/docs/pico-8_manual.html#Quirks_of_PICO_8) but the TL;DR version:

  • SIN and COS in PICO-8 take values from 0..1 instead of 0..360, so if you're working with degrees, you need to divide by 360 (there may be better ways to do this, but that's how I usually do it).

  • SIN is also inverted, so SIN(90/360) actually returns -1 instead of 1.
P#99864 2021-11-09 13:51

One of the "quirks" of PICO-8 is: COS() and SIN() take 0..1 instead of 0..PI*2, and SIN() is inverted

I recommend you read the docs about SIN() for an example of how to implement a more familiar COS() and SIN() (if you so choose) and for a better understanding of how those functions work.

P#99865 2021-11-09 13:57

Thanks for clearing that up for me, it makes sense now

P#99886 2021-11-09 22:26

[Please log in to post a comment]