/** Given the position of a target and the position and radius of an obstacle, this method calculates a position * {@code distanceFromBoundary} away from the object's bounding radius and directly opposite the target. It does this by scaling * the normalized "to obstacle" vector by the required distance away from the center of the obstacle and then adding the result * to the obstacle's position. * @param obstaclePosition * @param obstacleRadius * @param targetPosition * @return the hiding position behind the obstacle. */ protected T getHidingPosition (T obstaclePosition, float obstacleRadius, T targetPosition) { // Calculate how far away the agent is to be from the chosen // obstacle's bounding radius float distanceAway = obstacleRadius + distanceFromBoundary; // Calculate the normalized vector toward the obstacle from the target toObstacle.set(obstaclePosition).sub(targetPosition).nor(); // Scale it to size and add to the obstacle's position to get // the hiding spot. return toObstacle.scl(distanceAway).add(obstaclePosition); }
@Override public Ray<T>[] updateRays () { rays[0].start.set(owner.getPosition()); rays[0].end.set(owner.getLinearVelocity()).nor().scl(length).add(rays[0].start); return rays; }
@Override protected SteeringAcceleration<T> calculateRealSteering (SteeringAcceleration<T> steering) { // We just do the opposite of seek, i.e. (owner.getPosition() - target.getPosition()) // instead of (target.getPosition() - owner.getPosition()) steering.linear.set(owner.getPosition()).sub(target.getPosition()).nor().scl(getActualLimiter().getMaxLinearAcceleration()); // No angular acceleration steering.angular = 0; // Output steering acceleration return steering; }
@Override protected SteeringAcceleration<T> calculateRealSteering (SteeringAcceleration<T> steering) { // Try to match the position of the character with the position of the target by calculating // the direction to the target and by moving toward it as fast as possible. steering.linear.set(target.getPosition()).sub(owner.getPosition()).nor().scl(getActualLimiter().getMaxLinearAcceleration()); // No angular acceleration steering.angular = 0; // Output steering acceleration return steering; }
@Override protected SteeringAcceleration<T> calculateRealSteering (SteeringAcceleration<T> steering) { steering.setZero(); centerOfMass = steering.linear; int neighborCount = proximity.findNeighbors(this); if (neighborCount > 0) { // The center of mass is the average of the sum of positions centerOfMass.scl(1f / neighborCount); // Now seek towards that position. centerOfMass.sub(owner.getPosition()).nor().scl(getActualLimiter().getMaxLinearAcceleration()); } return steering; }
@Override protected SteeringAcceleration<T> calculateRealSteering (SteeringAcceleration<T> steering) { T targetPosition = target.getPosition(); // Get the square distance to the evader (the target) float squareDistance = steering.linear.set(targetPosition).sub(owner.getPosition()).len2(); // Work out our current square speed float squareSpeed = owner.getLinearVelocity().len2(); float predictionTime = maxPredictionTime; if (squareSpeed > 0) { // Calculate prediction time if speed is not too small to give a reasonable value float squarePredictionTime = squareDistance / squareSpeed; if (squarePredictionTime < maxPredictionTime * maxPredictionTime) predictionTime = (float)Math.sqrt(squarePredictionTime); } // Calculate and seek/flee the predicted position of the target steering.linear.set(targetPosition).mulAdd(target.getLinearVelocity(), predictionTime).sub(owner.getPosition()).nor() .scl(getActualMaxLinearAcceleration()); // No angular acceleration steering.angular = 0; // Output steering acceleration return steering; }
@Override public Ray<T>[] updateRays () { float velocityAngle = owner.vectorToAngle(owner.getLinearVelocity()); // Update ray 0 owner.angleToVector(rays[0].start, velocityAngle - HALF_PI).scl(sideOffset).add(owner.getPosition()); rays[0].end.set(owner.getLinearVelocity()).nor().scl(length); // later we'll add rays[0].start; // Update ray 1 owner.angleToVector(rays[1].start, velocityAngle + HALF_PI).scl(sideOffset).add(owner.getPosition()); rays[1].end.set(rays[0].end).add(rays[1].start); // add start position to ray 0 rays[0].end.add(rays[0].start); return rays; }
@Override public Ray<T>[] updateRays () { T ownerPosition = owner.getPosition(); T ownerVelocity = owner.getLinearVelocity(); float velocityAngle = owner.vectorToAngle(ownerVelocity); // Update central ray rays[0].start.set(ownerPosition); rays[0].end.set(ownerVelocity).nor().scl(rayLength).add(ownerPosition); // Update left ray rays[1].start.set(ownerPosition); owner.angleToVector(rays[1].end, velocityAngle - whiskerAngle).scl(whiskerLength).add(ownerPosition); // Update right ray rays[2].start.set(ownerPosition); owner.angleToVector(rays[2].end, velocityAngle + whiskerAngle).scl(whiskerLength).add(ownerPosition); return rays; }
.mulAdd(minOutputCollision.normal, owner.getBoundingRadius() + distanceFromBoundary).sub(owner.getPosition()).nor() .scl(getActualLimiter().getMaxLinearAcceleration());
relativePosition.nor().scl(-getActualLimiter().getMaxLinearAcceleration());
steering.linear.set(internalTargetPosition).sub(owner.getPosition()).nor() .scl(getActualLimiter().getMaxLinearAcceleration());
} else { steering.linear.set(internalTargetPosition).sub(owner.getPosition()).nor().scl(maxLinearAcceleration);
/** Given the position of a target and the position and radius of an obstacle, this method calculates a position * {@code distanceFromBoundary} away from the object's bounding radius and directly opposite the target. It does this by scaling * the normalized "to obstacle" vector by the required distance away from the center of the obstacle and then adding the result * to the obstacle's position. * @param obstaclePosition * @param obstacleRadius * @param targetPosition * @return the hiding position behind the obstacle. */ protected T getHidingPosition (T obstaclePosition, float obstacleRadius, T targetPosition) { // Calculate how far away the agent is to be from the chosen // obstacle's bounding radius float distanceAway = obstacleRadius + distanceFromBoundary; // Calculate the normalized vector toward the obstacle from the target toObstacle.set(obstaclePosition).sub(targetPosition).nor(); // Scale it to size and add to the obstacle's position to get // the hiding spot. return toObstacle.scl(distanceAway).add(obstaclePosition); }
@Override public Ray<T>[] updateRays () { rays[0].start.set(owner.getPosition()); rays[0].end.set(owner.getLinearVelocity()).nor().scl(length).add(rays[0].start); return rays; }
@Override protected SteeringAcceleration<T> calculateRealSteering (SteeringAcceleration<T> steering) { // Try to match the position of the character with the position of the target by calculating // the direction to the target and by moving toward it as fast as possible. steering.linear.set(target.getPosition()).sub(owner.getPosition()).nor().scl(getActualLimiter().getMaxLinearAcceleration()); // No angular acceleration steering.angular = 0; // Output steering acceleration return steering; }
@Override protected SteeringAcceleration<T> calculateRealSteering (SteeringAcceleration<T> steering) { // We just do the opposite of seek, i.e. (owner.getPosition() - target.getPosition()) // instead of (target.getPosition() - owner.getPosition()) steering.linear.set(owner.getPosition()).sub(target.getPosition()).nor().scl(getActualLimiter().getMaxLinearAcceleration()); // No angular acceleration steering.angular = 0; // Output steering acceleration return steering; }
@Override protected SteeringAcceleration<T> calculateRealSteering (SteeringAcceleration<T> steering) { steering.setZero(); centerOfMass = steering.linear; int neighborCount = proximity.findNeighbors(this); if (neighborCount > 0) { // The center of mass is the average of the sum of positions centerOfMass.scl(1f / neighborCount); // Now seek towards that position. centerOfMass.sub(owner.getPosition()).nor().scl(getActualLimiter().getMaxLinearAcceleration()); } return steering; }
@Override protected SteeringAcceleration<T> calculateRealSteering (SteeringAcceleration<T> steering) { T targetPosition = target.getPosition(); // Get the square distance to the evader (the target) float squareDistance = steering.linear.set(targetPosition).sub(owner.getPosition()).len2(); // Work out our current square speed float squareSpeed = owner.getLinearVelocity().len2(); float predictionTime = maxPredictionTime; if (squareSpeed > 0) { // Calculate prediction time if speed is not too small to give a reasonable value float squarePredictionTime = squareDistance / squareSpeed; if (squarePredictionTime < maxPredictionTime * maxPredictionTime) predictionTime = (float)Math.sqrt(squarePredictionTime); } // Calculate and seek/flee the predicted position of the target steering.linear.set(targetPosition).mulAdd(target.getLinearVelocity(), predictionTime).sub(owner.getPosition()).nor() .scl(getActualMaxLinearAcceleration()); // No angular acceleration steering.angular = 0; // Output steering acceleration return steering; }
@Override public Ray<T>[] updateRays () { float velocityAngle = owner.vectorToAngle(owner.getLinearVelocity()); // Update ray 0 owner.angleToVector(rays[0].start, velocityAngle - HALF_PI).scl(sideOffset).add(owner.getPosition()); rays[0].end.set(owner.getLinearVelocity()).nor().scl(length); // later we'll add rays[0].start; // Update ray 1 owner.angleToVector(rays[1].start, velocityAngle + HALF_PI).scl(sideOffset).add(owner.getPosition()); rays[1].end.set(rays[0].end).add(rays[1].start); // add start position to ray 0 rays[0].end.add(rays[0].start); return rays; }
@Override public Ray<T>[] updateRays () { T ownerPosition = owner.getPosition(); T ownerVelocity = owner.getLinearVelocity(); float velocityAngle = owner.vectorToAngle(ownerVelocity); // Update central ray rays[0].start.set(ownerPosition); rays[0].end.set(ownerVelocity).nor().scl(rayLength).add(ownerPosition); // Update left ray rays[1].start.set(ownerPosition); owner.angleToVector(rays[1].end, velocityAngle - whiskerAngle).scl(whiskerLength).add(ownerPosition); // Update right ray rays[2].start.set(ownerPosition); owner.angleToVector(rays[2].end, velocityAngle + whiskerAngle).scl(whiskerLength).add(ownerPosition); return rays; }