I'm trying to make the line move when variable "g" increases
function _init() g=1 end function _update() if (btn(2)) g+=1 if (btn(3)) g-=1 end function _draw() cls() circ(64, 64, 20, 7) x = 64 + cos(g()) * 20 y = 64 + sin(g()) * 20 line(64, 64, x, y) print(g) end |
If anyone has any tips for me, or a good sin() cos() tutorial, it would be a great help.
1
You've got the right idea there's just a couple things going wrong here.
g is a variable not a function so in draw you should have:
x = 64 + cos(g) * 20 y = 64 + sin(g) * 20 |
The second thing is that angles in Pico8 are numbers between 0 and 1. So 0 is 0 degrees and 1 is 360 degrees. Since you're increasing/decreasing g by 1, what you're actually doing doing a full 360 rotation each time.
Change update to something like this:
function _update() if (btn(2)) g+=1/360 if (btn(3)) g-=1/360 end |
That'll give you a change of 1 degree each time g changes.
1
This site has tutorials about trigonometry for pico8: https://demoman.net/?a=trig-for-games
[Please log in to post a comment]