Page 1 of 1

what's wrond with radians?

Posted: Tue Nov 01, 2016 8:20 am
by BenVlad
so, i decided to create a simple space shooter, where you drive you space ship. In development process, i had a problem with this engine's strange radian system:
er1.png
er1.png (85.54 KiB) Viewed 2798 times
When i install radian manually, all is good:

Code: Select all

if love.keyboard.isDown('r') then
		player.x = height/2
		player.y = width/2
		player.XYspeed.X = 0
		player.XYspeed.Y = 0
		player.deg = math.pi
	end
So, what i should do in this case, gues?

Re: what's wrond with radians?

Posted: Tue Nov 01, 2016 9:31 am
by ivan
Hello, can you post some more code so we can take a look?
You can convert between radians and degrees using:

Code: Select all

degrees = math.deg(math.pi)
radians = math.rad(degrees)
Once you know the heading of your ship you can use:

Code: Select all

velocityX = math.cos(headingInRadians)*velocity
velocityY = math.sin(headingInRadians)*velocity
Also, a while ago I wrote a short tutorial on vector math that you might find useful:
http://2dengine.com/doc/gs_vector.html