So I comply with the unique gdx-ai documentation and created 2 circles to check Steering conduct.
The picture exhibits arrival behaviour however I’m nonetheless fairly misplaced about how they work.
Screen class:
public void present() {
pCircle = new ShapeRenderer();
pCircle.setProjectionMatrix(mCamera.mixed);
sCircle = new SteeringCircle(pCircle, 15, 128*5, 128, Color.BLUE);
goal = new SteeringCircle(pCircle, 15, 128,128*3 , Color.CYAN);
/*
Wander<Vector2> wanderSB = new Wander<Vector2>(sCircle);
wanderSB.setEnabled(true);
wanderSB.setTarget(goal);*/
Arrive<Vector2> arriveSB = new Arrive<Vector2>(sCircle, goal).setTimeToTarget(0.1f).setArrivalTolerance(10f).setDecelerationRadius(25f);
sCircle.setBehavior(arriveSB);
}
@Override
public void render(float delta) {
Gdx.gl.glClearColor(63 / 255f, 128 / 255f, 70 / 255f, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
mCamera.replace();
mTiledMapRenderer.setView(mCamera);
mTiledMapRenderer.render();
sCircle.replace(delta);
sCircle.render();
goal.render();
mBatch.setProjectionMatrix(mCamera.mixed);
mBatch.start();
mBatch.draw(img, 128, 0);
mBatch.finish();
}
SteeringCircle class:
public SteeringCircle(ShapeRenderer circle ,float boundingRadius, float x, float y, Color coloration) {
pCircle = circle;
mColor = coloration;
this.place = newVector();
this.place.x = x;
this.place.y = y;
this.boundingRadius = boundingRadius;
this.maxLinearSpeed = 50;
this.maxLinearAcceleration = 5000;
this.linearVelocity = new Vector2(15,15);
this.maxAngularSpeed = 30;
this.maxLinearAcceleration = 5;
this.tagged = false;
this.steeringOutput = new SteeringAcceleration<Vector2>(new Vector2());
}
@Override
public Location<Vector2> newLocation() {
return null;
}
public void replace (float delta) {
if (steeringBehavior != null) {
// Calculate steering acceleration
steeringBehavior.calculateSteering(steeringOutput);
// Apply steering acceleration to maneuver this agent
applySteering(steeringOutput, delta);
}
}
non-public void applySteering (SteeringAcceleration<Vector2> steering, float time) {
// Update place and linear velocity. Velocity is trimmed to most pace
this.place.mulAdd(linearVelocity, time);
this.linearVelocity.mulAdd(steering.linear, time).restrict(this.getMaxLinearSpeed());
// Update orientation and angular velocity
if (independentFacing) {
this.orientation += angularVelocity * time;
this.angularVelocity += steering.angular * time;
} else {
// For non-independent going through we now have to align orientation to linear velocity
float newOrientation = calculateOrientationFromLinearVelocity(this);
if (newOrientation != this.orientation) {
this.angularVelocity = (newOrientation - this.orientation) * time;
this.orientation = newOrientation;
}
}
}
-
For the arrival behaviour, the blue circle will transfer from the unique place in the direction of the Cyan circle and comes again to the circle backwards and forwards. I assumed the blue circle is meant to cease when arriving the cyan circle which it did not. How can I make it cease at arrival? what’s mistaken with the codes?
-
For the wander behaviour, the blue circle simply strikes north-east route and by no means goes again to the cyan circle. I assumed it would wander round however it did not. Any recommendation on what is required to alter to make the wander behaviour occurs?
Also, does anybody know what ought to Location returns? Isn’t Vector2 place already has the situation?