Space Battle!!

Started by
14 comments, last by fixxorion 20 years, 6 months ago
Hi all! I'm trying to create the effect of ships fighting against each other. I can get the spaceships to follow after each other, but I'm having a little problem makin it look good. Sometimes, when the ships swing around to make another shot at their target, they just snap around...instead of swerving around like a "real" spaceship would do. :D Right now, I'm just taking ship A's position and subtracting that from ship B's position, and then adding the resulting vector to ship A's velocity. How would I go about actually making the spaceships perform more realistically...like having limits on how fast it can swerve, how fast it can move, etc. I've tried looking through GameDev for a solution, but I'm not sure what to look for. I've seen people recommend Craig Reynolds steering behavior, and I've checked it out. However, my problem is a bit different. Any help on this would be GREATLY appreciated! I'm desperate! Thanks, fixxorion [edited by - fixxorion on October 6, 2003 6:56:08 PM]
Advertisement
quote:Original post by fixxorion
Right now, I''m just taking ship A''s position and subtracting that from ship B''s position, and then adding the resulting vector to ship A''s velocity. How would I go about actually making the spaceships perform more realistically...

First of all, you''d be better off working with the velocity vector of ships A and B, rather than the position vectors. Deduct A''s velocity vector from B''s to get the relative velocity of A with respect to B.

To limit the amount that a ship can turn in a given frame update, apply a fractional time step to the thrust vector. Let''s say that a given ship can turn at 90 degrees per second. Then, if your frame rate is 60 fps, that ship can turn 1.5 degrees per frame. Get the idea? To make use of this with your current computation, you can do one of two things.

1) Compute the angle between the heading of B and the direction to A. i.e., how much does B need to turn by to be heading toward A''s last position. Work out how much of that can be turned in the next frame and adjust the heading of B accordingly.

2) Simply add a small left or right thrust vector to the ships velocity at each frame and rotate the ship so it is facing in the direction of its motion. This left or right thrust should cause the same angular displacement as the turn rate of the ship if it is to give the correct results.

Try these out and see which one is faster computationally and which one you like better.

If you need any more help, let us know.

Cheers,

Timkin

Thanks for the quick response!

I think I see what you mean. However, I don''t understand what you mean by not using their position vectors. Here''s some pseudocode of the little I have now:

//---------------------------------------

Vector vecTarget = new Vector(target.x, target.y, target.z);
Vector vecShip = new Vector(ship.x, ship.y, ship.z);

Vector displacement = vecTarget - vecShip;

ship.velocity += displacement;

//---------------------------------------


Do you mean I would need to find the rotation needed in X, Y, and Z to be pointing at the target? And then, over time, increment the rotation until it reaches that point?

Thanks again for the help,

fixxorion
I had an example I was going to send you, but apparently you''ve blocked your email adress.
quote:Original post by jack_1313
I had an example I was going to send you, but apparently you''ve blocked your email adress.


Hey jack_1313, I would love an example as well! Could you please email it to me at jasoo24 [at] hotmail.com?

Thanks!
Jason Arorajason@pubism.comhttp://www.pubism.com
That''d be awesome!

Here''s my email address:

fixxorion@softhome.net

Thanks,

fixxorion
Wait... before everyone gets excited I should point out a few things:

The example is 2D, overhead, and features two teams of Fighters,Bombers, and and a Cruiser dueling it out. However, the AI could eaisly be transfered to 3D.
The example is an exe, but I intend to explain how it works with another post a little later.
This AI is simple - the whole example took me about 30 minutes to create, but is efficiant. It is intended as a base from which to work off. When I made this, I wanted to keep it simple so I could have 100''s of ships fighting at once.

So I will send it, and if you are interested, please say and I will state exactly how the AI works, and offer suggestions on how to make it better. Also, I the example plays kind of like a move - because the AI has no random elements the battle is the same every time. If interested, I could make it so that you could lay down ships, and then run custom battles.
Yeah, please do send it, and if you have time, I would love to know how the AI actually works!

Thanks much!

fixxorion
Hi all

jack_1313, I am interested in this topic could you please post how the Fighters and AI works.

i would be grateful if you can send the example, this is my email

the_moon_warrior@yahoo.com

thankx
What I''m still unsure about is the method for getting the ship to turn around. As I understand it, you add a vector perpendicular to the current vector. In other words, you would need to do something like the following:

Vector ship;
Vector target;

// basically find a perpendicular vector of ship that points in
// the general direction of the target
ship += ship.perpendicularVector(target) / 5

Is this the right way to do it? If so, how would I do this in 3D?

Thanks,

fixxorion

This topic is closed to new replies.

Advertisement