Mugen87 / yuka

JavaScript library for developing Game AI.
https://mugen87.github.io/yuka/
MIT License
1.13k stars 91 forks source link

Steering handling in `Vehicle.update()` ignores `GameEntity.maxTurnRate` #49

Closed discordier closed 2 years ago

discordier commented 3 years ago

I am currently experimenting in combining goals and steering. I just stumbled over the fact that steering behavior application in Vehicle completely ignores the maxTurnRate defined in GameEntity.

I wonder if we should make steering in Vehicle aware of the maxTurnRate, as technically a vehicle is a derived class from GameEntity and therefore should adhere to the same constraints?

I feel however that implementing it will break existing functionality, as one can disable MovingEntity.updateOrientation.

So we have currently the following feature matrix (ordered by class inheritance): Method maxTurnRate supported updateOrientation supported steering supported
GameEntity.update() true false false
MovingEntity.update() false (problem) true false
Vehicle.update() false (problem) true true
Mugen87 commented 3 years ago

maxTurnRate is actually only intended for rotateTo(). When implementing the method, I have considered to make maxTurnRate a parameter in order to avoid the impression you could use the property for other things, too. However it seemed more convenient to me if the app could configure the turn rate on entity level.

Maybe clarifying the documentation of maxTurnRate is sufficient for now.

discordier commented 3 years ago

Another way would be to reorganize the behaviors to not "slide" the entity but rotate and move it where possible. So the steering force would become a "desired direction" and then we would rotate to said direction and move forward.

I am currently trying to throw together an example for moving a car across hills and stumble into issues of behaviors and the Vehicle class. Currently it appears as if the Vehicle class is only suitable in very narrow use cases and not when:

Maybe I am missing something obvious here?

Non the less, the documentation currently is pretty vague about what properties are used for calculation and therefore it would be cool to enhance it. :+1:

Mugen87 commented 3 years ago

Non the less, the documentation currently is pretty vague about what properties are used for calculation

That's true. Most parts of the documentation mainly describe the class structure but with too less explanations.

the vehicle does not support "in place" rotation and therefore has a limit on rotation radius.

The problem is that the steering model tries to be physically correct whereas non-force based methods like rotateTo() are not. However, there is no problem to combine both approaches in a game. Meaning when the vehicle (or moving entity) stays sill (when it has a zero speed), you can use rotateTo() without issues.

any vector has a non 0 Y-coordinate

That depends on the use case. If you consider FollowPathBehavior, it works fine in 3D space. SeekBehavior works fine if you model something like a rocket.

Keep in mind that games which utilizes navigation meshes, FollowPathBehavior and OnPathBehavior are the most common behaviors. The others are already more specific.

Mugen87 commented 2 years ago

Clarified maxTurnRate via bd9d885e77f43244df91507142f9ad8f7d1e277f.