Hello All,
I am new to Angelscript and I am wanting to create steering behaviors for enemy AI. I haven't found any Angelscript examples on the web for Seek, Flee, Follow, Arrive, Collision avoidance, etc so far. I have successfully written an A* routine, but that's about it.
Does anyone know of any steering behaviors written in Angelscript ? Can you post a link?
Since I wasn't able to find any steering behaviors written in Angelscript, I decided to try to convert a "Flee" behavior written in C. Unfortunately there is a command I can't seem to find in Angelscript that the C code uses. Specifically, the "Limit" command. I think it is equivalent to a "SCALAR" command? I am not sure. Anyone know? Thanks in advance for any help.
This is the code for the "Flee" behavior below:
class Vehicle {
PVector location;
PVector velocity;
PVector acceleration;
Additional variable for size
float r;
float maxforce;
float maxspeed;
Vehicle(float x, float y) {
acceleration = new PVector(0,0);
velocity = new PVector(0,0);
location = new PVector(x,y);
r = 3.0;
Arbitrary values for maxspeed and force; try varying these!
maxspeed = 4;
maxforce = 0.1;
}
Our standard “Euler integration” motion model
void update() {
velocity.add(acceleration);
velocity.limit(maxspeed); <<<------------ THIS LINE USES THE COMMAND "LIMIT"
location.add(velocity);
acceleration.mult(0);
}
Newton’s second law; we could divide by mass if we wanted.
void applyForce(PVector force) {
acceleration.add(force);
}
Our seek steering force algorithm
void seek(PVector target) {
PVector desired = PVector.sub(target,location);
desired.normalize();
desired.mult(maxspeed);
PVector steer = PVector.sub(desired,velocity);
steer.limit(maxforce);
applyForce(steer);
}
void display() {
Vehicle is a triangle pointing in the direction of velocity; since it is drawn pointing up, we rotate it an additional 90 degrees.
float theta = velocity.heading() + PI/2;
fill(175);
stroke(0);
pushMatrix();
translate(location.x,location.y);
rotate(theta);
beginShape();
vertex(0, -r*2);
vertex(-r, r*2);
vertex(r, r*2);
endShape(CLOSE);
popMatrix();
}