Page 1 of 1

is my ai technique ok?

Posted: Sat Aug 19, 2006 4:01 pm
by VanOccupanther
hi

My game is a space game. The little ship flys around the screen in side view (ground, sky, clouds).

i'm now trying to make ai for the enemies.

Currently my ai consists of a state method. Each ship has a "type" number. The type number shows what state the enemy ship is in. So far there is type #12 and type #13. Type #12 moves the ship down diagonally to the right from the top of the screen. Once the ship reaches a certian scanline it automatically changes to type #13. Type #13 moves the ship straight down vertically to the bottom of the screen. When the ship reaches the top of the screen again it becomes type $12. And this is repeated.

i want to do this:

Image

The enemy would be moving along the black lines from state to state. But there are two problems with this.

1. A more complicated path would require more states. Wouldn't this way be too much code?

2, How would you make an enemy move along a curvy path? Is there a different way to do ai for this?

please help.

Re: is my ai technique ok?

Posted: Sat Aug 19, 2006 4:44 pm
by tepples
VanOccupanther wrote:1. A more complicated path would require more states. Wouldn't this way be too much code?
If the states are represented as data, not code, then all states can share the same code.
2, How would you make an enemy move along a curvy path?
Depends on what kind of curvy path you're talking about. Do you know the differential equations for Newtonian kinematics (displacement, velocity, acceleration)?

Re: is my ai technique ok?

Posted: Sat Aug 19, 2006 6:37 pm
by VanOccupanther
tepples wrote:
VanOccupanther wrote:1. A more complicated path would require more states. Wouldn't this way be too much code?
If the states are represented as data, not code, then all states can share the same code.
Thank You! brilliant! Would that be something like this:

Store x_portion, x_portion_decimal, y_portion, and y_portion_decimal for each state. Then make it read the first 4 bytes and move the enemy accordingly? But how do you know when to change to the next state?
2, How would you make an enemy move along a curvy path?
Depends on what kind of curvy path you're talking about. Do you know the differential equations for Newtonian kinematics (displacement, velocity, acceleration)?
no :(

Posted: Sat Aug 19, 2006 7:10 pm
by tepples
To change to the next state, you can define thresholds based on time spent in a given state or based on collision with the background.

Here are Newton's laws of motion:
  • acceleration(t) = diff(velocity(t), t)
  • velocity(t) = diff(displacement(t), t)
Integrated with respect to t:
  • velocity(t) = integrate(acceleration(t), t)
  • displacement(t) = integrate(velocity(t), t)
Euler numerical integration means you should do the following in each time step:
  1. acceleration := some function of the game state
  2. velocity := velocity + acceleration
  3. displacement := displacement + velocity

Posted: Sun Aug 20, 2006 3:54 pm
by VanOccupanther
Thank You!
tepples wrote:To change to the next state, you can define thresholds based on time spent in a given state or based on collision with the background.
i think thresholds of time spent in a given state is the way to go for me. There are four bytes per state (y_portion, y_portion_decimal, x_portion, x_portion_decimal). Since y_protion can only be 1 or 0, use the rest of the bits to hold the time period of the state. That gives 0 - 127 possible values.

How do you go from this to time spent? Is it like, a time of 2 would be 2 cycles through the code? But, doesnt the code execute really fast? Am i totally wrong here?

Posted: Sun Aug 20, 2006 6:50 pm
by tepples
A time of 120 would be 120 cycles through the code. If your game executes its game loop at 60.1 Hz like most NES games do, that equals two seconds.