Page 1 of 1

Need some math help

Posted: Tue Jan 27, 2015 4:06 am
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

Re: Need some math help

Posted: Tue Jan 27, 2015 5:54 am
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

Re: Need some math help

Posted: Tue Jan 27, 2015 6:45 am
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.