[ad_1]
So I observe the unique gdx-ai documentation and created 2 circles to check Steering habits.
The picture exhibits arrival behaviour however I’m nonetheless fairly misplaced about how they work.
Display class:
public void present() {
pCircle = new ShapeRenderer();
pCircle.setProjectionMatrix(mCamera.mixed);
sCircle = new SteeringCircle(pCircle, 15, 128*5, 128, Colour.BLUE);
goal = new SteeringCircle(pCircle, 15, 128,128*3 , Colour.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, Colour shade) {
pCircle = circle;
mColor = shade;
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) {
// Replace place and linear velocity. Velocity is trimmed to most velocity
this.place.mulAdd(linearVelocity, time);
this.linearVelocity.mulAdd(steering.linear, time).restrict(this.getMaxLinearSpeed());
// Replace orientation and angular velocity
if (independentFacing) {
this.orientation += angularVelocity * time;
this.angularVelocity += steering.angular * time;
} else {
// For non-independent going through we've 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 path and by no means goes again to the cyan circle. I assumed it would wander round but it surely did not. Any recommendation on what is required to vary to make the wander behaviour occurs?
Additionally, does anybody know what ought to Location returns? Is not Vector2 place already has the placement?
[ad_2]