# TheMoebius

Member

20

112 Neutral

• Rank
Member
1. ## interception algorithm in 2D space compensating for acceleration?

For practicality reasons I can't actually have a 100% realistic space game. So I have a max speed because if a ship got up to a very high speed it would make it very difficult to interact with other ships, land on planets, etc. Which is why this is a space arcade game rather than a space simulation. I also don't have any rotational acceleration or momentum, but I do have a max turn rate. Quote:The problem with this is that theoretically, it takes an infinite amount of time for the westward velocity to dissapate... In a mathematically perfect world it would take an infinite amount of time for westward velocity to dissipate, but since floats can only be finitely small, that westward velocity does indeed taper off after a reasonable amount of time. Quote:Rather than just apply acceleration in the direction you want to go, you need to actively eliminate velocity that is going in contrary directions; can't rely on the max-speed drag thing (that shouldnt even exist in space anyway). Yep, thats basically what my current algorithm does but you also have to take into account that distance you will have displaced yourself while decelerating velocity going in the "contrary direction" and you have to predict that because otherwise you'll end up going around you target in a spiraling circle. [Edited by - TheMoebius on October 24, 2006 12:19:09 AM]
2. ## interception algorithm in 2D space compensating for acceleration?

The tricky thing is, there are two variables that control position - heading and time. P(h, t) position as a function of heading and time. I can't easily find the inverse of that if all I know is position. The same problem exists an a numerical, 'brute force' solution because I would have to try different angles AND different times. Also, I think that if I have to perform those operations 36-64 times per ship per frame it could grow to be a very big problem very quickly. I expect this problem will require higher level math. I've taken calc 2 before but I'm not sure how to apply it here.
3. ## interception algorithm in 2D space compensating for acceleration?

I'm experimenting with a 2D space arcade style simulation and I'm trying to develop an intercept algorithm that will compensate for current velocity. Currently I have it very close, but not quite. Since this is space I don't have instant acceleration when I want to turn a ship, it doesn't drive like a car. I need to realistically apply thrust in the correct direction to cancel out my current velocity moving in the wrong direction so that I will intercept the target (which could be moving or still). Here's my current algorithm for generating the heading. This is called every frame: //duplicate the line to the target. reflected line will turn into the offset trajectory MyVector2 reflectedLine = toTarget; //uses cross product to derive the angle between the line toTarget and the current velocity line float angleToRotate = toTarget.signedAngleFromVector(&mvVelocityPerSec).valueRadians(); //scale the angled offset according to how much time or distance it has to correct its movement angleToRotate = angleToRotate * mvVelocityPerSec.length() / toTarget.length(); //cout << "DEBUG: angleToRotate = " << angleToRotate << endl; reflectedLine.rotate(Radian(angleToRotate)); MyVector2 vCompensator = reflectedLine - toTarget; //figure the amount of lateral decelleration per second so we can derive //the distance we will have travelled off course by the time we get back on course float compensationPerSec = (mvVelocityPerSec.normalisedCopy() - toTarget.normalisedCopy()).length() * mvVelocityPerSec.length(); float d = vCompensator.squaredLength() / (2*(compensationPerSec)); //add the dist we will have travelled off course to the compensation trajectory vCompensator = vCompensator + d; compensatedTrajectory = toTarget + vCompensator; //compensatedTrajectory = reflectedLine; But the compensation for current velocity always ends up just a little short, even with non-moving targets. One possible factor that I didn't account for because I'm not sure how is my max-speed limiter. It just scales back a vector to its max magnitude if it has gone over the limit that frame. So if I start out going due west then turn my ship and accelerate due north, the westward velocity will eventually have tapered out and I'll be going due north. There may be a better way of doing this. Someone must have done this before. Any suggestions or know of any algorithms that could help me? I've already searched on this site and google but nothing seems to quite fit.
4. ## space trajectories compensating for off-course momentum

I'm experimenting with a 2D top-down space arcade style game and I'm trying to get the realistic physics to work. I want to be able to dynamically spawn waypoints or to have a ship intercept another moving ship which means that its trajectory has to be recalculated every frame and I can't use spline path methods. Currently I'm trying to measure the velocity in the direction perpendicular to a line pointing to the target and figure how much acceleration is needed to cancel that movement. The orientation towards the target is offset by the thrust required to decellerate that lateral velocity to 0 + the distence it will have travelled off course during that deceleration. Of course my algorithm is flawed because it doesn't quite make it - the ship still swings a little wide of its target. I have a video clip demonstrating the problem: http://www.zacwittedesign.com/epiar_trajectory_demo.avi Here is my algorithm which is calculated every frame: MyVector2 reflectedLine = toTarget; //duplicate the line to the target. reflected line will turn into the offset trajectory //uses cross product to derive the angle between the line toTarget and the current velocity line float angleToRotate = toTarget.signedAngleFromVector(&mvVelocityPerSec).valueRadians(); //scale the angled offset according to how much time or distance it has to correct its movement angleToRotate = angleToRotate * mvVelocityPerSec.length() / toTarget.length(); //cout << "DEBUG: angleToRotate = " << angleToRotate << endl; reflectedLine.rotate(Radian(angleToRotate)); MyVector2 vCompensator = reflectedLine - toTarget; //figure the amount of lateral decelleration per second so we can derive the distance we will have travelled off course float compensationPerSec = (mvVelocityPerSec.normalisedCopy() - toTarget.normalisedCopy()).length() * mvVelocityPerSec.length(); float d = vCompensator.squaredLength() / (2*(compensationPerSec)); //add the compensation trajectory to the dist we will have travelled off course vCompensator = vCompensator + d; compensatedTrajectory = toTarget + vCompensator;
5. ## Predicting time required for manuvers

In programming my AI I want a ship to be able to turn around and apply thrust to come to a stop at a certain point. I want it to act just like a human controlled ship so I can't really cheat and position the ship myself - I'd like it to use the same accelerate and turn functions as the player input uses. How do I predict the amount of time needed for the ship to turn around since the framerate is inconsistent? I have a turn rate per second that is multiplied by timeSinceLastFrame, the same with acceleration. I can predict the number of frames needed to turn around but I need timeSinceLastFrame to keep the animation speed consistent and when I introduce that factor into the equasion, the ship could undershoot or overshoot its target. How do other people solve this?
6. ## angle between vectors

Quote:Original post by mooserman352 Moebius, As I had posted above, that is indeed the fastest and easiest way to do this. Note that Grain's method is equivalent mathematically, and adds somewhat of a geometric interpretation to what is being done. Yeah, thats the one I used. Thx for that.
7. ## angle between vectors

Isn't cross product the easiest and cheapest? At least if I'm not concerned with the actual angle and only which way to turn. This is my code. double y = mvHeading.x * target->z - target->x * mvHeading.z; if (y<0) { turnLeft(); } else if (y>=0) { turnRight(); }
8. ## angle between vectors

Is there a way just to get the direction that is less expensive?
9. ## angle between vectors

Whats the most efficient way to find the angle between two vectors? basically I have a current heading and a target heading and I want to know if I should call my turnRight() or turnLeft() function based on if the angle is positive or negetive. I'm using Ogre with the Vector3 class, but I'm only working on a 2 dimentional plane in this case. API doc is here http://www.ogre3d.org/docs/api/html/classOgre_1_1Vector3.html It has a dotProduct() function and a getRotationTo() function.
10. ## the overloaded function that just wouldn't

I knew it had to be me. I've been working with Java too much lately. Thanks for the coffee. (no pun intended?)
11. ## the overloaded function that just wouldn't

I have a class called Ship and a child class called ShipAI. The update() function in ShipAI is supposed to overload the update() function is ship, but its not. Here's a bit of the code from the header file. class Ship { (snip) public: Ship(); //this is called every frame by WorldMgr void update(Real timeSinceLastFrame); (snip) }; class ShipAI: public Ship { (snip) public: ShipAI(); void update(Real timeSinceLastFrame); }; I have a std::vector of pointers to Ship and each frame is cycles through that list and calls the update() function. Here's the code: vector<Ship*>::iterator i; for (i=mShips.begin(); i!=mShips.end(); i++){ //cout << "updating ship" << (*i)->getShipID() << endl; (*i)->update(evt.timeSinceLastFrame); } The list includes Ship's and ShipAI's. I would have thought that when it came across a ShipAI class it would call ShipAI::update() instead of Ship::update(), but it doesn't. I have cout traces in the ShipAI constructor and the Ship constructor and in ShipAI::update(). On world creation I manually spawn one Ship class and one ShipAI class. I see the output of Ship twice and ShipAI once so I know it's being created properly. Am I an idiot or whats going on? Thx.
12. ## choosing a 3D engine

But I know there are a whole lot of 3D engines out there. What about all of them listed on this page? http://abattoir.wolfpaw.net/personal/gamelibs.php#3dgfx Does anyone know anything about these: CrystalSpace (www.crystalspace3d.org) GmbH (www.radonlabs.de/nebula.html) NeonEngine (www.realityrift.com/technology/neoengine) OGRE (www.ogre3d.org) I've looked at all of the above, but how can I tell which is best for a paticular purpose? There is an example that OGRE gives - the game Axiomatic - which some screenshots appear similar to the look I'm going for. But I bet the other engines could do much of the same thing. What should I look for when weighing my options? Thanks.
13. ## choosing a 3D engine

Thanks for the reply. Yeah, the game is written in C++ and I'm pretty confident in my coding abilities there. I'm currently using SDL and have a simple 2D sprite thing set up, but I'm looking to move beyond that. I should also say that being an open source game, I want it to run on most platforms, so I'm going the Open GL route rather than Direct X. Torque unfortunately isn't open source so that puts it out of the question. I could, concievably write my own engine, but it would be soooo much work and strikes me as reinventing the wheel. Graphics programming is important, but not what I want to concentrate on learning. I have more of an interest in AI. Any other suggestions?
14. ## choosing a 3D engine

I'm working on a space adventure/roleplaying/arcade type mixture and I'm trying to choose a 3D engine to use here. I've looked at this list of engines http://abattoir.wolfpaw.net/personal/gamelibs.php#3dgfx but there are so many and I don't have enough experience with any to easily choose between them without spending a week experimenting on all of them. It actually will ideadly be quite simple. Also, the game will be released under GPL, so the engine license needs to be compatible with that. It's basically a 2D game - the camera maintains a constant overhead view and all the ships or objects exist on one plane, but there should be a bit of deapth to it. For example, I want to model the ships in 3D so they can actually bank and roll around when they turn instead of having a simple sprite rotate. And I'd also like to add simple particle effects for weapons, explosions, shields, etc. Much like Chromium BSU http://www.reptilelabour.com/software/chromium/screen1.htm Are there any recommendations that I should look into in more deapth?