Created
May 7, 2013 01:32
-
-
Save jrenner/5529658 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private Vector2 getVelocityCorrectionSteerpoint(Vector2 waypoint) { | |
if (waypoint == null) { | |
return null; | |
} | |
Vector2 selfVel = body.getLinearVelocity().cpy(); | |
// if this is not a regular waypoint, but instead a point we should chase | |
// (like a moving enemy target) then we want to correct for the target's velocity as well | |
if (isChaseTargetPosition(waypoint)) { | |
// add target's velocity to the waypoint, so we can predict movement | |
Vector2 targVel = targetEntity.body.getLinearVelocity(); | |
waypoint.add(targVel); | |
} | |
Vector2 selfPos = body.getPosition(); | |
// desired velocity is target's position minus our position | |
Vector2 desiredVelocity = waypoint.cpy().sub(selfPos); | |
// The correction we need to make to the waypoint is | |
// the difference between desire velocity and current velocity | |
Vector2 steeringCorrection = desiredVelocity.sub(selfVel); | |
// new waypoint = old waypoint + steering correction | |
Vector2 steeringCorrectionPoint = steeringCorrection.add(waypoint); | |
return steeringCorrectionPoint; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment