Advertisement Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

112 Neutral

About TheMoebius

  • Rank
  1. 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. 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. 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. 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: 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. 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. TheMoebius

    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. TheMoebius

    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. TheMoebius

    angle between vectors

    Is there a way just to get the direction that is less expensive?
  9. 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 It has a dotProduct() function and a getRotationTo() function.
  10. I knew it had to be me. I've been working with Java too much lately. Thanks for the coffee. (no pun intended?)
  11. 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. TheMoebius

    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? Does anyone know anything about these: CrystalSpace ( GmbH ( NeonEngine ( OGRE ( 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. TheMoebius

    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. TheMoebius

    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 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 Are there any recommendations that I should look into in more deapth?
  15. TheMoebius

    SDL Input Library & Input Discussion [renamed]

    Hey guys, I'm writing the input class for an open source game I'm working on called Epiar ( ) and I'm looking for your input on my methods for handling the whole input system. I'm attaching the same cInput class proposal that I sent to the other developers. Because the current cInput needs to be reworked to make more extensible and easier to add actions, etc. My newly proposed cInput class I think does the job and also gets rid of keys.cpp. It uses Drew Benton's SDL Input Library found at Now I want your comments and feedback on how you think it will work and don't be nice. I'm just figuring this stuff out as I go so I'm sure theres room for improvement. Since I'm a bit of a programming n00b theres probably a bunch of syntactical errors and I'm not totally sure if I used enum right, but those are minor details that I can work out when I get the compile errors. I'm really interested in the over all method of doing this. keys.xml has declarations like: <controlsFlyMode> <fire1> <device>mou</device> <value>1</value> </fire1> <orbit> <device>key</device> <value>9</device> </orbit> </controlsFlyMode> <controlsSelectMode> <select> <device>mou</device> <value>1</value> </select> <fire1> <device>key</device> <value>64</value> </fire1> </controlsSelectMode> There are two different control modes because we (or at least I?) were/was talking about being able to toggle between flying mode where you'd use the mouse to point the ship and the mouse1 button would be fire, etc. But then you could hit tab to select other ships, interact with the HUD, open the right click menu, etc. Many of the controls would be the same,but it can pretty easily be taken out. The value for the keyboard is the int value of SDL_a or KMOD_CTRL or whatever. They're just plain and simple ints. The SDL documentation has these values in a table somewhere. The values for the mouse are simply the button numbers. LoadConfig() fills the following arrays with values from the keys config file. Of course the index matches the enumed action values like ACT_FIRE1 and ACT_ORBIT. int flyModeDevices[numberOfKeys]; int flyModeValues[numberOfKeys]; int selectModeDevices[numberOfKeys]; int selectModeValues[numberOfKeys]; Problems to solve that I can think of off the top of my head: * We should figure out an easy way to make it case insensetive. It's also probably not terribly hard and could be done either in LoadConfig() or in GetActionValue(), so SDLK_a and SDLK_A return the same int. * I don't show anything for setting and getting new keys or input, but thats fairly trivial. * Alternatively the XML doc could be laid out like <fire1>mou1</fire1><orbit>key9</orbit> depending on how cConfig works, I can't remember at the moment. And then you could just chop it up in LoadConfig or something. * This input library doesn't currently support joystick functions, but the developer said he was going to add it and even if it doesn't finish it in time, we could do it ourselves. ----------------------------------------------------------------------------------- // The following uses Drew Benton's "SDL input library" found at // enum actions { ACT_FIRE1, ACT_ORBIT //etc,etc } cInput::cInput() { SDL_Event Event; LoadConfig("keys.xml") //see note above Input inputClass; //Drew Benton's SDL Input Library //I'm sure there will be more to add here } void cInput::LoadConfig(string configFile) { //see note above } int cInput::GetActionDevice(int action) { if (flyMode == true) { return flyModeDevice[action]; } else { return selectModeDevice[action]; } } int cInput::GetActionValue(int action) { if (flyMode == true) { return flyModeValue[action]; } else { return selectModeValue[action]; } } bool cInput::testAction (int thisAction) { switch( GetActionDevice(thisAction) ) { case 1: if (inputClass.isKeyPressed( GetActionValue(thisAction) ) ) { return true; } case 2: if (inputClass.isButtonPressed( GetActionValue(thisAction) ) ) { return true; } break; case 3: //no joystick support in inputClass yet, but its going to be added break; } return false; } void cInput::resetKey (int thisAction) { // works much the same way as testAction, but it uses setKeyUp() or setButtonUp() // so the action happens only once. } //this function is called in Epiar's update cycle void cInput::Update() { //this chunk of code is from Drew Benton's demo included with the library while ( SDL_PollEvent(&Event) ) { if ( Event.type == SDL_QUIT ){ //do whatever we have to do to tell Epiar to quit } // Here we first call the Poll function with the current event // inside our polling loop InputClass.Poll(Event); } // Then we just have to call the update function to take the data // from the Poll event and update the class InputClass.Update(); //Now test each game action. if (testAction(ACT_FIRE1)) { player->fireWeapon(1); } if (testAction(ACT_ORBIT)) { player->orbit(target); resetKey(ACT_ORBIT); //for one time "toggle" type actions } if (testAction(ACT_SELECT)) { //get the target by looking at whatever is at the current mouse location. //get the mouse location using InputClass.GetMouseX() and InputClass.GetMouseY() player->setTarget(something); resetKey(ACT_SELECT); } [Edited by - TheMoebius on July 31, 2005 2:22:34 PM]
  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!