Hi everyone, I know this is a common question but my searches are not turning up good solutions (ones that work).
I have a flight simulator / jet fighter game. I have other airplanes (enemy targets) flying around in the world. I want to shoot a guided missile at the target. My original approach for this works most of the time, but sometimes fails.
What I have done is found my missile's heading vector, and the vector between the missile and the target. I take the cross product of the 2 vectors to get my rotation axis vector. The angle of rotation is found by arccosine of the dot product of the cross product of my missile & target vectors. Since I do not want the missile to turn directly at the target immediately, I limit the rotation to 2 degrees. After rotating, I move the missile along its forward vector, by its speed.
To explain the failure in this, let me give in an example. The game starts & out in front of my airplane is the target. For this example both objects are flying forward. If I fire the missile, it goes straight for the target and hits.
However, if I roll my airplane over (upside down) the missile seems to turn the wrong direction. It will often make a big loop and eventually find the target and destroy it. It seems that the rotation angle should be negative in this case, but I don't know how to determine if I need to do so.
Here is some basic code to demonstrate:
[source lang="java"]Vector3D targvec = new Vector3D(targetmatrix[12], targetmatrix[13], targetmatrix[14]);Vector3D R1pos = new Vector3D(R1Matrix[12], R1Matrix[13], R1Matrix[14]);Vector3D R1head = new Vector3D(R1Matrix[8], R1Matrix[9], R1Matrix[10]);Vector3D newtargvec = targvec.subtract(R1pos);newtargvec = newtargvec.normalize();R1head = R1head.normalize();float angle = R1head.angleBetween(newtargvec); // acos(R1head.dotProduct(newtargvec)Vector3D rotaxis = R1head.crossProduct(newvec);rotaxis.normalize();if (angle > 2){ angle = 2;Matrix.rotateM(R1Matrix, 0, (float) angle, rotaxis.getX(), rotaxis.getY(), rotaxis.getZ());setMoveForwardMatrix(tempMatrix, (movedist),R1Matrix[8], R1Matrix[9], R1Matrix[10]);Matrix.multiplyMM(R1Matrix, 0, tempMatrix, 0, R1Matrix, 0); [/source]
 Home
 » Viewing Profile: Topics: JM33
Interested in a FREE copy of HTML5 game maker Construct 2?
We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!
Sign up from the righthand sidebar on our homepage and read Tuesday's newsletter for details!
We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.
JM33
Member Since 04 May 2011Offline Last Active Dec 16 2012 12:55 PM
Community Stats
 Group Members
 Active Posts 28
 Profile Views 966
 Submitted Links 0
 Member Title Member
 Age Age Unknown
 Birthday Birthday Unknown

Gender
Not Telling
Topics I've Started
Incremental rotation towards target 3D
07 November 2012  11:26 PM
Common Video Game Term Translations
12 January 2012  11:11 PM
I had an idea for a table of common video game terms and translation into common languages. I wasn't thinking of a complex glossary, maybe just 2550 of the most common terms that would be used in almost every video game. For example, score, high score, level, settings/options, controls, play/start, quit/exit, lives (number of), back/next, forward/previous. Mostly the terms that a video game menu would include. Members here could add input as to their native languages to improve the accuracy.
I've been searching the web for a while now and have not come across anything like this. Surely most of these can be easily translated with Google translate or something like it, but some words don't always translate the same in the context of a video game.
I think this would be a useful tool for developers here, what do you guys think?
I've been searching the web for a while now and have not come across anything like this. Surely most of these can be easily translated with Google translate or something like it, but some words don't always translate the same in the context of a video game.
I think this would be a useful tool for developers here, what do you guys think?
Multiple moving objects
27 May 2011  06:06 AM
I am trying to write a basic game and am looking for some advice. I am working with opengl for android. I'm sure I am going about this all backwards, but I am just learning as I go. So far I just have a basic 3d airplane & world to fly around in. Basically my airplane always stays at 0,0,0 and I have a created rotation & translation matrices that move my lanscape/sky around.
Now I want to add some rockets to my plane (because blowing stuff up is more fun). So I'm wondering what would be the best way to do this. My rockets will be attached to the plane, but when fired should travel straight away from the plane. (I want to keep this simple, so heat seekers and smart bombs are probably going to be totally out of my skill level).
I have tried a couple of ideas, and limited success. One is to keep the rocket with the plane, basically never moving until fired. The main problem I am having with this approach is that once the rocket is fired, if the plane moves, so does the rocket. The other way is to put this rocket in the world and make it move around as if it were attached to the plane. I really have struggled with this. I can't even get the rocket to move with the plane, let alone worry about what to do when it is fired. I tried creating an inverse of the matrix which moves the world. I don't know if my math was wrong, or if this is even the right idea.
Any help or suggestions would be appreciated. Just thought I would ask what the best / most common solution is before I keep struggling with something that won't work. Maybe there is another way I haven't considered, such as making the world stay still and moving my airplane and camera with gluLookat. Thanks in advance.
Now I want to add some rockets to my plane (because blowing stuff up is more fun). So I'm wondering what would be the best way to do this. My rockets will be attached to the plane, but when fired should travel straight away from the plane. (I want to keep this simple, so heat seekers and smart bombs are probably going to be totally out of my skill level).
I have tried a couple of ideas, and limited success. One is to keep the rocket with the plane, basically never moving until fired. The main problem I am having with this approach is that once the rocket is fired, if the plane moves, so does the rocket. The other way is to put this rocket in the world and make it move around as if it were attached to the plane. I really have struggled with this. I can't even get the rocket to move with the plane, let alone worry about what to do when it is fired. I tried creating an inverse of the matrix which moves the world. I don't know if my math was wrong, or if this is even the right idea.
Any help or suggestions would be appreciated. Just thought I would ask what the best / most common solution is before I keep struggling with something that won't work. Maybe there is another way I haven't considered, such as making the world stay still and moving my airplane and camera with gluLookat. Thanks in advance.
Update up, forward, right vectors.
04 May 2011  03:55 AM
I am trying to write my first game, and want to create a simple airplane / flight type of game. I have been brushing up on my vector math but am getting stuck. At this point I'm just working out some pseudocode so I can just get an airplane flying around the world. Here's the basic idea of what I am trying to do:
My airplane will start out flying level and I will be able to start with up, right, and forward/heading vectors. On each frame the plane will move along the forward vector to its new position. If the user inputs up/down the pitch will be affected by "n" degrees, and the same for left/right and the roll affecting the up vector. I am planning ahead for yaw, though I haven't worked out the user control yet.
So I am trying to figure out how I update the up/right/forward vectors based on the degree of rotation. I have found lots of information about how to calculate the axis or the angle of rotation. Perhaps I am going about this in a harder way than necessary, but I know how I want to use these vectors and am sure it will work once I figure out how to calculate the new vectors.
I am using Opengl (Android) and want to use the gluLookat function. It simply accepts values of eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ. Obviously I will need a new up vector here for each frame, and of course my airplane will not always be aligned with the world up vector. Calculating the other values I have solved, based on knowing the updated vector.
I will simplify my question to just one rotation. I have a forward, right, and up vector. I receive input to move pitch up and I know the number of degrees. My rotation axis is the right vector. Given the rotation axis and amount of rotation (in degrees), how do I find the new up & foward vectors?
Thanks in advance!
My airplane will start out flying level and I will be able to start with up, right, and forward/heading vectors. On each frame the plane will move along the forward vector to its new position. If the user inputs up/down the pitch will be affected by "n" degrees, and the same for left/right and the roll affecting the up vector. I am planning ahead for yaw, though I haven't worked out the user control yet.
So I am trying to figure out how I update the up/right/forward vectors based on the degree of rotation. I have found lots of information about how to calculate the axis or the angle of rotation. Perhaps I am going about this in a harder way than necessary, but I know how I want to use these vectors and am sure it will work once I figure out how to calculate the new vectors.
I am using Opengl (Android) and want to use the gluLookat function. It simply accepts values of eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ. Obviously I will need a new up vector here for each frame, and of course my airplane will not always be aligned with the world up vector. Calculating the other values I have solved, based on knowing the updated vector.
I will simplify my question to just one rotation. I have a forward, right, and up vector. I receive input to move pitch up and I know the number of degrees. My rotation axis is the right vector. Given the rotation axis and amount of rotation (in degrees), how do I find the new up & foward vectors?
Thanks in advance!