libgdx / gdx-ai

Artificial Intelligence framework for games based on libGDX or not. Features: Steering Behaviors, Formation Motion, Pathfinding, Behavior Trees and Finite State Machines
Apache License 2.0
1.18k stars 241 forks source link

Are steering behaviors working with Box2D linear damping? #74

Closed lukz closed 6 years ago

lukz commented 7 years ago

I'm working on 2D top down game and I'm trying to make heavy enemy which slowly builds up his speed and crash into the wall. His body can be affected by external forces (push back on hit, attract by magnet etc.) so he has pretty big linear damping.

I'm trying to achieve described behavior by using Arrive Steering Behavior but I can't make him accelerate slowly.

Is there any way to make Arrive SB work in such situation?

I've made Box2dArriveTest with my parameters: Box2dCustomArriveTest.zip

character = createSteeringEntity(world, container.greenFish, false);
character.setMaxLinearSpeed(8);
character.setMaxLinearAcceleration(40);

MassData massData = new MassData();
massData.center.set(character.getBody().getMassData().center);
massData.I = character.getBody().getMassData().I;
massData.mass = 1f;

...

final Arrive<Vector2> arriveSB = new Arrive<Vector2>(character, target) //
    .setTimeToTarget(0.1f) //
    .setArrivalTolerance(0.001f) //
    .setDecelerationRadius(0.5f);
davebaol commented 7 years ago

Sorry for the delayed response, I was on vacation. Also, I'm not so used to box2d. Have you got it working in the meantime?

lukz commented 7 years ago

Nope. In this particular case I've just switched to manually apply force to the body without steering behavior but problem can get back with more complex enemy types where SB would be very useful. All entities in the game require some linear damping.

Relsig commented 6 years ago

This should probably be closed, I'm not sure if this was an issue at some point, but it isn't currently. linear damping works as intended so long as you apply forces to the body (or better yet impulses, since they account for timestep automagically) instead of setting the linear speed.

davebaol commented 6 years ago

@Relsig Thanks for your feedback