Gahh!! how do i do this?
help!
how do I make a ship in real time 3D dodge 3D asteroids?
if you need more information tell me
--m_nPostCount++
Determine distance between ship and asteroid, and if they are close enough to be considered a risk, work out which direction is best to avoid the asteroid, then turn.
After careful deliberation, I have come to the conclusion that Nazrix is not cool. I am sorry for any inconvienience my previous mistake may have caused. We now return you to the original programming
Stange questions and strange answers sometimes . I mean the answer certainly answers the question, but that can''t be what he was hoping for .
Now, I suppose the ship is a sail ship, right? So changing the ship''s direction probably changes its speed. I also don''t quite see what problem the fact it''s in 3D involves.. The problem seems exactly the same to me in 2D. Your ship is moving on a 2D plane (unless you take waves into accounts for ship''s height?).
You probably can figure out the impact point of the asteroid, and if it happens to be a danger,consider two possible "moves" : turning right of X degrees, and turning left of X degrees. And testing in each case if that change of direction avoids the impact, increasing X regularly. To refine a bit, you could test if the ship is going to be impacted if he just stops moving. If it''s the case, then you need to only consider the direction change that increases the ship''s speed. If it''s not the case, then maybe you can also consider droping the sails to slow the ship...
Err just thought of it at second thought.... Is it a space ship by any chance? Then it involves 3D indeed. You make a "colision risk" test function for the asteroid and ship that will consider the ship doesn''t change direction or speed (easy if to do if the asteroid also has a linear path and constant speed, use cubes or some other simple shape for the ship and asteroid for the collision test. I would then first consider dropping constantly and upping constantly the speed of the ship without changing direction, if it doesn''t avoid the impact (it will be the case for instance if the asteroid comes from the front, or just goes too fast), then consider turning while geting the speed to max speed (if the space ship turns slowlier when he goes faster, it complicates things a lot though...).
For the turning, of course, you should determine in wich part of the cube envelop representing the ship the asteroid would hurt the ship, with linear movements. Make the ship turn towards the opposite direction.
Hope this helps...
David Antonini
Now, I suppose the ship is a sail ship, right? So changing the ship''s direction probably changes its speed. I also don''t quite see what problem the fact it''s in 3D involves.. The problem seems exactly the same to me in 2D. Your ship is moving on a 2D plane (unless you take waves into accounts for ship''s height?).
You probably can figure out the impact point of the asteroid, and if it happens to be a danger,consider two possible "moves" : turning right of X degrees, and turning left of X degrees. And testing in each case if that change of direction avoids the impact, increasing X regularly. To refine a bit, you could test if the ship is going to be impacted if he just stops moving. If it''s the case, then you need to only consider the direction change that increases the ship''s speed. If it''s not the case, then maybe you can also consider droping the sails to slow the ship...
Err just thought of it at second thought.... Is it a space ship by any chance? Then it involves 3D indeed. You make a "colision risk" test function for the asteroid and ship that will consider the ship doesn''t change direction or speed (easy if to do if the asteroid also has a linear path and constant speed, use cubes or some other simple shape for the ship and asteroid for the collision test. I would then first consider dropping constantly and upping constantly the speed of the ship without changing direction, if it doesn''t avoid the impact (it will be the case for instance if the asteroid comes from the front, or just goes too fast), then consider turning while geting the speed to max speed (if the space ship turns slowlier when he goes faster, it complicates things a lot though...).
For the turning, of course, you should determine in wich part of the cube envelop representing the ship the asteroid would hurt the ship, with linear movements. Make the ship turn towards the opposite direction.
Hope this helps...
David Antonini
David Antonini.
With several asteroids the problem becomes way more complicated of course. Probably possible to figure out first wich asteroids are dangerous (passing close enough to the ship''s line to collide if the ship modifies his course). Then determine the plane that the most dangerous of these asteroids (the one who would hit the ship first) hits last. That brings the problem somewhat back to 2D by making the ship turn within this plane, though you have time to take into account as the plane gets crossed by the asteroids at given periods of time. Then maybe it''s possible to use some A* to figure out the best path?
David Antonini.
Extend the 3D world into a literal 4D volume, where the 4th dimension is time. Extruding the 3 dimensions of space through the 4th dimension of time creates a 4D statespace, which can be searched for a passage using A*. To extrude this 4th dimension you''ll have to run the simulation ahead of time to work out where all the asteroids will be, given velocity, gravitational pull and collisions. This will give you a (hopefully) pre-determined path for flying the ship.
No, I''m not serious.
Yes, it would work.
Mike
No, I''m not serious.
Yes, it would work.
Mike
quote: Original post by Sigloxx
I suppose the ship is a sail ship, right?
Im really sorry but *lol* a sail ship among asteroids? Interesting concept.
Well if you combine the answers given, you should have what you need. First calcuate wich asteroids will even get close to the ship, then use a bounding sphere around the asteroids, and use it to plan a route between them. and "flatten" the problem to 2D when charting a course. that should get you going I think.
Don't we all still remember and miss the day we plotted our first pixel?
December 02, 2002 07:53 PM
quote: Original post by Bad_ManiacOriginal post by Sigloxx
I suppose the ship is a sail ship, right?
Im really sorry but *lol* a sail ship among asteroids? Interesting concept.
Wait another 9 months and you should be able to get it. Basically, in my next game I''ve moved the whole Buccaner theme into space, altered wind sails for solar sails, updated the technology to perform the same functional stuff (cannons to mass launchers, vibro blades for cutlasses. My inspiration was an episode of Dr WHo where they were having a sailing race in space.
And I''ve got to admit it''s a blast. Especially, when my boarding crew, launches across the space void to capture to try and grab ahold of the enemy ship to board. Total chaos but in a fun way. Just 48 more art milestones and I can publish this sucker.
quote: Original post by Anonymous Poster (Sigloxx, right?)
Wait another 9 months and you should be able to get it. Basically, in my next game I''ve moved the whole Buccaner theme into space...
Sounds like a certain upcoming Disney movie... (Not a bad idea though!!)
Also, I don''t think MikeD''s idea really is all that ridiculous. I think it would provide you with a good, robust "AI." Just don''t search too far ahead in time.
For a really simple idea, you could instead just treat each asteroid in radius r as a repulsive particle; make the repulsion proportional to the magnitude of the component of the asteroid''s velocity vector that is pointing towards the ship. It''s a random thought, but it sounds elegant and reasonably effective.
Or, if you want, just whip up a Genetic Programming algorithm with a few basic functions for things like steering, thrust, and determining what the closest asteroids are, and let evolution do the work.
Hmmm... there may also be an obstacle avoidance steering behavior; run a Google search on "Steering Behaviors" and see what pops up.
Those are my only suggestions for now.
How about treating each asteroid as an origin of a force vector. Then, with the magnitude decrease proportional to distance squared, a far off asteroid gives less force than a close asteroid, and therefore less of a threat. If you have two close asteroids, then you sum the vectors of their "danger" forces and use the resultant vector as you escape path.
[Formerly "capn_midnight". See some of my projects. Find me on twitter tumblr G+ Github.]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement