N00B Question About Airplanes and Rockets
BlitzMax Forums/BlitzMax Beginners Area/N00B Question About Airplanes and Rockets
| ||
I am working on a little airplane game where you can fly around and dogfight and whatever you feel like doing, but I can not think of an easy way to solve a very simple problem. I have automidhandle on, because it needs to be on for the rotation to look realistic, but when I started adding bullets and collisions, the bullets hit the plane that shot them instantly because they 'spawn' in the middle of the plane. Normally, I could just have them start a couple pixels in one direction, but the problem is that the plane will be at all kinds of different rotations, so no one number will do the trick. The only solution I can think of would be to make a big long block of code that would supply numbers to add to the x and y coords based on the rotation, but it just feels like there should be an easier way. |
| ||
bulletx and bullety is where the bullet is to be created.local distFromPlane:float = 10 'adjust value for proper positioning bulletx:float = positionOfPlaneX + cos(angleOfPlane)*distanceFromPlane bullety:Float = positionOfplaneY + sin(angleOfPlane)*distanceFromPlane that is considering your plane image was made facing right, if it was made point up then subtract 90 from angleOfPlane for the calculation. |
| ||
That worked really well, except that somewhere around 270 degrees didn't work, but I will just keep tinkering. Thanks a ton!!! |
| ||
You could add the shooting plane as a field for each bullet, so the bullet knows who fired it. Then you don't make a collision if the target is the shooting plane. This could also be useful for score purposes - which player killed which enemy? |
| ||
do the angle subtracting at the equation:local distFromPlane:float = 10 'adjust value for proper positioning bulletx:float = positionOfPlaneX + cos(angleOfPlane-90)*distanceFromPlane bullety:Float = positionOfplaneY + sin(angleOfPlane-90)*distanceFromPlane |
| ||
A combination of both of your suggestions has worked magic :-) Thanks a ton! |
| ||
good to see it resolved. |
| ||
good to know that no matter where you post on the blitz blog, stanrol is watching over you ;) |