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
Need some math help
Re: Need some math help
Welcome to the forums.
I think you are talking about:
where a is the angle in radians and x and y is a 'unit' vector.
In practice you'll probably need something like:
I think you are talking about:
Code: Select all
x = math.cos(a)
y = math.sin(a)
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
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.
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.
Who is online
Users browsing this forum: Ahrefs [Bot] and 9 guests