how to judge arriveBehave over
Closed this issue · 1 comments
sorry for my pool english . i was wrtting a program to show a vehicle movement. i want a vehicle move to my target , so i use arriveBehave class. everytime the vehicle arrive the target ,the program will generate next target position. my problem is i don't know how to judge a arriveBehave is over , i try to use arriveBehaveObj.active to judge , but failed,and the vehicle move past the target and then return
The active flag is not something that is set by the engine. You as a developer can use it to indicate whether a steering behavior should be active or not.
Determining if a game entity has arrived at a specific position is use case specific. You normally do not perform an equality test with a target position since steering behaviors are too imprecise for this. Instead, it's best to check if the game entity is close enough. In Kickoff I have used the following routine:
/**
* Returns true if this player is at the position of its current steering target.
*
* @return {Boolean} Whether this player is at the position of its current steering target or not.
*/
atTarget() {
return this.position.squaredDistanceTo( this.steeringTarget ) < CONFIG.PLAYER_IN_TARGET_RANGE_SQ;
}
This actually represents the way humans or animals seek to a destination point. It's not necessary to exactly reach the target coordinate. Close enough is fine.