Smart Homing
I am trying to create(in 2d with c++) a spaceship game and wanted one of the enemies to follow and crash against you avoiding any obstacles in the way(Even if said obstacles are in motion). The way my ships move is first they have to rotate to face the direction they are moving and then they move.
Any ideas on how I could accomplish this?
So they can't rotate while moving? How quickly do they accelerate/decelerate? How quickly do they rotate?
They can move while rotating and they can rotate while moving. But they move towards the direction they are currently facing. They accelerate/deccelerate/rotate somewhat quickly(in a second to max speed/full rotation) though they don't get too fast.
<br><br>1. Check out <a href="http://www.gamedev.net/reference/articles/article1125.asp">Potential fields</a>. They're a nice way to do this.<br><br>2. However, potential fields are just a particular "flavor" of <i>planning algorithm</i>, so you might want to check out <a href="http://planning.cs.uiuc.edu/">Steve LaValle's (Free, Online, and Excellent) Planning Book</a> which is a great intro to lots of stuff in this area.<br><br>3. Another planning algorithm is called "RRTs" or "Rapidly-Exploring Random Trees" (see <a href="http://msl.cs.uiuc.edu/rrt/about.html">here</a>, for instance).<br><br>Any of these techniques would be worth looking at for your problem, from what you've described.
Quote: Original post by Antonym
They can move while rotating and they can rotate while moving. But they move towards the direction they are currently facing. They accelerate/deccelerate/rotate somewhat quickly(in a second to max speed/full rotation) though they don't get too fast.
Would this be a fair summary? (By the way, this kind of "state space model" is usually a very concise, unambiguous way to communicate how a spaceship -- or anything else -- behaves):
STATE: (x, y, v, theta) where - (x, y) = position - v = speed - theta = heading angle INPUTs: (u, omega) where - u = acceleration and braking - omega = steeringDYNAMICS: Continuous time: (d/dt) x = v cos(theta) (d/dt) y = v sin(theta) (d/dt) v = { u if 0 <= v <= vMax { 0 otherwise (d/dt) theta = omega (or, ) Discrete time: x[k+1] = x[k] + v cos(theta[k]) y[k+1] = y[k] + v sin(theta[k]) v[k+1] = max(min(v[k] + u, vMax), 0) theta[k+1] = theta[k] + omega
Quote: Original post by stonemetal
Sounds like ye olde steering behaviors are for you. See here
I think that's exactly the kind of stuff I am looking for though there is no source code or details on implementation :S. I am not good at all at math.
It's a library isnt it? The problem I have with using a library is I am already using a library to process my collision I feel I am pretty much not learning anything..
On a side note: How can I draw simple geometric shapes(Like in the applets) like circles of different colors, lines and so on(I'd like to start trying to implement this stuff and a very precise visual feedback aid would be nice). I use direct3d.
Quote: Original post by Antonym
I am trying to create(in 2d with c++) a spaceship game and wanted one of the enemies to follow and crash against you avoiding any obstacles in the way(Even if said obstacles are in motion). The way my ships move is first they have to rotate to face the direction they are moving and then they move.
Any ideas on how I could accomplish this?
I don't completely understand the dynamic you're describing, but I wonder about using a fuzzy logic solution. I think you could have fuzzy rules like:
/* Relationship to player */
if PLAYER_BEARING is TO_LEFT then TURN is LEFT
if PLAYER_BEARING is NEAR_FORWARD then TURN is CENTER
if PLAYER_BEARING is TO_RIGHT then TURN is RIGHT
if PLAYER_DISTANCE is NEAR then ACCELERATE is NEAR_ZERO
if PLAYER_DISTANCE is MEDIUM then ACCELERATE is LOW
if PLAYER_DISTANCE is FAR then ACCELERATE is HIGH
/* Relationship to nearest obstacle */
if OBSTACLE_BEARING is TO_LEFT and
OBSTACLE_DISTANCE is NEAR
then TURN is RIGHT
...and so on.
-Will Dwinnell
Data Mining in MATLAB
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement