Need some math help

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
waddlepon
Prole
Posts: 1
Joined: Tue Jan 27, 2015 4:00 am

Need some math help

Post by waddlepon »

I need to figure out how to calculate where to spawn a projectile based on the angle(in radians) of the ship spawning it. If anyone knows how to do this could you please help me?

________________
| |
| |
\ /
\ /
\ /
\ /
\ /
\ /
\ /
\/

/\
|
|
Spawn here no matter the angle
User avatar
ivan
Party member
Posts: 1911
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: Need some math help

Post by ivan »

Welcome to the forums.
I think you are talking about:

Code: Select all

x = math.cos(a)
y = math.sin(a)
where a is the angle in radians and x and y is a 'unit' vector.
In practice you'll probably need something like:

Code: Select all

sx, sy = center of the ship
d = how far from the center is the spawn point
a = angle in radians of the ship

x = math.cos(a)*d + sx
y = math.sin(a)*d + sy
Muris
Party member
Posts: 131
Joined: Fri May 23, 2014 9:18 am

Re: Need some math help

Post by Muris »

Here is a list of lua math functions:
http://lua-users.org/wiki/MathLibraryTutorial

Just random tip: Something I myself had completely missed is atan2. For example if you want to count angle you can pass both x and y at the same time, which makes it a lot easier because you don't yourself have to check in which quarter of circle the point is.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Majestic-12 [Bot], Semrush [Bot] and 48 guests