Hey there. I'm trying to start my second game using Lua and I decided to make a lunar lander game. It's going alright so far, but the main area I'm having trouble with is getting a correct force applied to my ship depending on its angle. Can anyone point me in the right direction as to what I could (or should) be using.
I'm using body:getAngle to get the angle of the ship and I'm just multiplying that by 70 to get a decent x value for the force I want to apply (probably not the best way to go about it ). I can't seem to find any way to turn the angle into a proper y value though.
Bring on the math, and thanks in advance for any help.
Getting force from an angle? [Solved]
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Getting force from an angle? [Solved]
Last edited by Freonce on Thu Aug 19, 2010 8:19 pm, edited 1 time in total.
Re: Getting force from an angle?
Well I think you can use tangent to get the slope. Don't ask me; I'm not a trig expert. I'm still not sure how you would change a slope into proper x and y values though.
Re: Getting force from an angle?
you should play Astropatrolonium. Its a great game.
http://love2d.org/forums/viewtopic.php?f=5&t=1716
Then look at its code where it says
----ship movement physik----
in function love.update(dt)
then a few lines down you find:
http://love2d.org/forums/viewtopic.php?f=5&t=1716
Then look at its code where it says
----ship movement physik----
in function love.update(dt)
then a few lines down you find:
Code: Select all
....
...
if (p.want_up) then
local thrust_fx = -sin(p.b:getAngle()) * ship_acc
local thrust_fy = -cos(p.b:getAngle()) * ship_acc
p.b:applyForce (thrust_fx, thrust_fy)
....
....
Re: Getting force from an angle?
If you want to know why, I recommend reading the "Linear algebra for game developers" by wolfire.
Here is Although this too fails to explain why the rotation works
Here is Although this too fails to explain why the rotation works
Re: Getting force from an angle?
what do you mean?vrld wrote:Although this too fails to explain why the rotation works
Re: Getting force from an angle?
Awesome!
Thanks for all the replies. I think that little snippet of code is just want I need. I was trying to use math.atan2 for some reason... I'll be sure to read those links as well. Understanding the why is a key part to learning all this, and having it stick.
I'll post an update when I get my ship working.
Thanks for all the replies. I think that little snippet of code is just want I need. I was trying to use math.atan2 for some reason... I'll be sure to read those links as well. Understanding the why is a key part to learning all this, and having it stick.
I'll post an update when I get my ship working.
Re: Getting force from an angle? [Solved]
Everything is working alright now. Just have some velocity bugs I need to work out. Thanks again everyone!
Who is online
Users browsing this forum: No registered users and 3 guests