@Override public void applyConfigs(SteeringBehaviorComponent steeringBC) { Wander wander = (Wander)steeringBC.behavior; Steerable steerable = wander.getOwner(); steerable.setMaxLinearSpeed(MAX_LINEAR_SPEED); steerable.setMaxLinearAcceleration(MAX_LINEAR_ACCELERATION); steerable.setMaxAngularSpeed(MAX_ANGULAR_SPEED); steerable.setMaxAngularAcceleration(MAX_ANGULAR_ACCELERATION); wander.setWanderRadius(0.1f); wander.setTimeToTarget(0.1f); wander.setDecelerationRadius(1f); wander.setFaceEnabled(false); wander.setWanderOrientation(250f); }
@Override public void applyConfigs(SteeringBehaviorComponent steeringBC) { Wander wander = (Wander)steeringBC.behavior; Steerable steerable = wander.getOwner(); steerable.setMaxLinearSpeed(MAX_LINEAR_SPEED); steerable.setMaxLinearAcceleration(MAX_LINEAR_ACCELERATION); steerable.setMaxAngularSpeed(MAX_ANGULAR_SPEED); steerable.setMaxAngularAcceleration(MAX_ANGULAR_ACCELERATION); wander.setWanderRadius(0.1f); wander.setTimeToTarget(0.1f); wander.setDecelerationRadius(0f); wander.setFaceEnabled(false); wander.setWanderOrientation(250f); }
@Override public void applyConfigs(SteeringBehaviorComponent steeringBC) { Wander wander = (Wander)steeringBC.behavior; Steerable steerable = wander.getOwner(); steerable.setMaxLinearSpeed(MAX_LINEAR_SPEED); steerable.setMaxLinearAcceleration(MAX_LINEAR_ACCELERATION); steerable.setMaxAngularSpeed(MAX_ANGULAR_SPEED); steerable.setMaxAngularAcceleration(MAX_ANGULAR_ACCELERATION); //wander.setTarget(loc); wander.setWanderRadius(5f); wander.setTimeToTarget(0.1f); wander.setDecelerationRadius(3f); wander.setFaceEnabled(false); wander.setWanderOrientation(250f); }
@Override public boolean reportNeighbor (Steerable<T> neighbor) { toAgent.set(owner.getPosition()).sub(neighbor.getPosition()); float distanceSqr = toAgent.len2(); float maxAcceleration = getActualLimiter().getMaxLinearAcceleration(); // Calculate the strength of repulsion through inverse square law decay float strength = getDecayCoefficient() / distanceSqr; if (strength > maxAcceleration) strength = maxAcceleration; // Add the acceleration // Optimized code for linear.mulAdd(toAgent.nor(), strength); linear.mulAdd(toAgent, strength / (float)Math.sqrt(distanceSqr)); return true; }
@Override public boolean reportNeighbor (Steerable<T> neighbor) { // Calculate the position of the hiding spot for this obstacle T hidingSpot = getHidingPosition(neighbor.getPosition(), neighbor.getBoundingRadius(), target.getPosition()); // Work in distance-squared space to find the closest hiding // spot to the owner float distance2 = hidingSpot.dst2(owner.getPosition()); if (distance2 < distance2ToClosest) { distance2ToClosest = distance2; bestHidingSpot.set(hidingSpot); return true; } return false; }
@Override public void applyConfigs(SteeringBehaviorComponent steeringBC) { Pursue pursue = (Pursue)steeringBC.behavior; Steerable steerable = pursue.getOwner(); steerable.setMaxLinearSpeed(MAX_LINEAR_SPEED); steerable.setMaxLinearAcceleration(MAX_LINEAR_ACCELERATION); steerable.setMaxAngularSpeed(MAX_ANGULAR_SPEED); steerable.setMaxAngularAcceleration(MAX_ANGULAR_ACCELERATION); pursue.setMaxPredictionTime(0.85f); }
/** Creates a {@code RayConfigurationBase} for the given owner and the specified number of rays. * @param owner the owner of this configuration * @param numRays the number of rays used by this configuration */ @SuppressWarnings("unchecked") public RayConfigurationBase (Steerable<T> owner, int numRays) { this.owner = owner; this.rays = new Ray[numRays]; for (int i = 0; i < numRays; i++) this.rays[i] = new Ray<T>(owner.getPosition().cpy().setZero(), owner.getPosition().cpy().setZero()); }
@Override public void applyConfigs(SteeringBehaviorComponent steeringBC) { Seek seek = (Seek)steeringBC.behavior; Steerable steerable = seek.getOwner(); steerable.setMaxLinearSpeed(MAX_LINEAR_SPEED); steerable.setMaxLinearAcceleration(MAX_LINEAR_ACCELERATION); steerable.setMaxAngularSpeed(MAX_ANGULAR_SPEED); steerable.setMaxAngularAcceleration(MAX_ANGULAR_ACCELERATION); }
@Override public void applyConfigs(SteeringBehaviorComponent steeringBC) { Pursue pursue = (Pursue)steeringBC.behavior; Steerable steerable = pursue.getOwner(); steerable.setMaxLinearSpeed(MAX_LINEAR_SPEED); steerable.setMaxLinearAcceleration(MAX_LINEAR_ACCELERATION); steerable.setMaxAngularSpeed(MAX_ANGULAR_SPEED); steerable.setMaxAngularAcceleration(MAX_ANGULAR_ACCELERATION); }
@Override public void applyConfigs(SteeringBehaviorComponent steeringBC) { Arrive arrive = (Arrive)steeringBC.behavior; Steerable steerable = arrive.getOwner(); steerable.setMaxLinearSpeed(MAX_LINEAR_SPEED); steerable.setMaxLinearAcceleration(MAX_LINEAR_ACCELERATION); steerable.setMaxAngularSpeed(MAX_ANGULAR_SPEED); steerable.setMaxAngularAcceleration(MAX_ANGULAR_ACCELERATION); arrive.setArrivalTolerance(0.5f); arrive.setDecelerationRadius(10f); arrive.setTimeToTarget(0.005f); }
public static Arrive createArrive(float x, float y, Steerable steerable){ SteerLocation loc = new SteerLocation(); loc.getPosition().set(x, y); Arrive arrive = new Arrive(steerable, loc); arrive.setTarget(loc); arrive.setOwner(steerable); return arrive; }
/** Creates a {@code CentralRayWithWhiskersConfiguration} for the given owner where the central ray has the specified length and * the two whiskers have the specified length and angle. * @param owner the owner of this configuration * @param rayLength the length of the central ray * @param whiskerLength the length of the two whiskers (usually shorter than the central ray) * @param whiskerAngle the angle in radians of the whiskers from the central ray */ public CentralRayWithWhiskersConfiguration (Steerable<T> owner, float rayLength, float whiskerLength, float whiskerAngle) { super(owner, 3); this.rayLength = rayLength; this.whiskerLength = whiskerLength; this.whiskerAngle = whiskerAngle; }
/** Creates a {@code FieldOfViewProximity} for the specified owner, agents and cone area defined by the given radius and angle * in radians. * @param owner the owner of this proximity * @param agents the agents * @param radius the radius of the cone area * @param angle the angle in radians of the cone area */ public FieldOfViewProximity (Steerable<T> owner, Iterable<? extends Steerable<T>> agents, float radius, float angle) { super(owner, agents); this.radius = radius; setAngle(angle); this.lastTime = 0; this.ownerOrientation = owner.getPosition().cpy().setZero(); this.toAgent = owner.getPosition().cpy().setZero(); }
@Override public int findNeighbors (ProximityCallback<T> callback) { int neighborCount = 0; for (Steerable<T> currentAgent : agents) { // Make sure the agent being examined isn't the owner if (currentAgent != owner) { if (callback.reportNeighbor(currentAgent)) { neighborCount++; } } } return neighborCount; }
/** Creates an {@code Interpose} behavior for the specified owner and agents using the the given interposing ratio. * @param owner the owner of this behavior * @param agentA the first agent * @param agentB the other agent * @param interpositionRatio a number between 0 and 1 indicating the percentage of the distance between the 2 agents that the * owner should reach, where 0 is agentA position and 1 is agentB position. */ public Interpose (Steerable<T> owner, Steerable<T> agentA, Steerable<T> agentB, float interpositionRatio) { super(owner); this.agentA = agentA; this.agentB = agentB; this.interpositionRatio = interpositionRatio; this.internalTargetPosition = newVector(owner); }
/** Creates a {@code RaycastObstacleAvoidance} behavior. * @param owner the owner of this behavior * @param rayConfiguration the ray configuration * @param raycastCollisionDetector the collision detector * @param distanceFromBoundary the minimum distance to a wall (i.e., how far to avoid collision). */ public RaycastObstacleAvoidance (Steerable<T> owner, RayConfiguration<T> rayConfiguration, RaycastCollisionDetector<T> raycastCollisionDetector, float distanceFromBoundary) { super(owner); this.rayConfiguration = rayConfiguration; this.raycastCollisionDetector = raycastCollisionDetector; this.distanceFromBoundary = distanceFromBoundary; this.outputCollision = new Collision<T>(newVector(owner), newVector(owner)); this.minOutputCollision = new Collision<T>(newVector(owner), newVector(owner)); }
/** Creates a {@code CollisionAvoidance} behavior for the specified owner and proximity. * @param owner the owner of this behavior * @param proximity the proximity of this behavior. */ public CollisionAvoidance (Steerable<T> owner, Proximity<T> proximity) { super(owner, proximity); this.firstRelativePosition = newVector(owner); this.firstRelativeVelocity = newVector(owner); this.relativeVelocity = newVector(owner); }
@Override public boolean reportNeighbor (Steerable<T> neighbor) { // Calculate the time to collision relativePosition.set(neighbor.getPosition()).sub(owner.getPosition()); relativeVelocity.set(neighbor.getLinearVelocity()).sub(owner.getLinearVelocity()); float relativeSpeed2 = relativeVelocity.len2(); // Collision can't happen when the agents have the same linear velocity. // Also, note that timeToCollision would be NaN due to the indeterminate form 0/0 and, // since any comparison involving NaN returns false, it would become the shortestTime, // so defeating the algorithm. if (relativeSpeed2 == 0) return false; float timeToCollision = -relativePosition.dot(relativeVelocity) / relativeSpeed2; // If timeToCollision is negative, i.e. the owner is already moving away from the the neighbor, // or it's not the most imminent collision then no action needs to be taken. if (timeToCollision <= 0 || timeToCollision >= shortestTime) return false; // Check if it is going to be a collision at all float distance = relativePosition.len(); float minSeparation = distance - (float)Math.sqrt(relativeSpeed2) * timeToCollision /* shortestTime */; if (minSeparation > owner.getBoundingRadius() + neighbor.getBoundingRadius()) return false; // Store most imminent collision data shortestTime = timeToCollision; firstNeighbor = neighbor; firstMinSeparation = minSeparation; firstDistance = distance; firstRelativePosition.set(relativePosition); firstRelativeVelocity.set(relativeVelocity); return true; }
/** Creates a {@code BlendedSteering} for the specified {@code owner}, {@code maxLinearAcceleration} and * {@code maxAngularAcceleration}. * @param owner the owner of this behavior. */ public BlendedSteering (Steerable<T> owner) { super(owner); this.list = new Array<BehaviorAndWeight<T>>(); this.steering = new SteeringAcceleration<T>(newVector(owner)); }
/** Creates a {@code FollowPath} behavior for the specified owner, path, path offset, maximum linear acceleration and prediction * time. * @param owner the owner of this behavior * @param path the path to be followed by the owner * @param pathOffset the distance along the path to generate the target. Can be negative if the owner is to move along the * reverse direction. * @param predictionTime the time in the future to predict the owner's position. Can be 0 for non-predictive path following. */ public FollowPath (Steerable<T> owner, Path<T, P> path, float pathOffset, float predictionTime) { super(owner); this.path = path; this.pathParam = path.createParam(); this.pathOffset = pathOffset; this.predictionTime = predictionTime; this.arriveEnabled = true; this.internalTargetPosition = newVector(owner); }
/** Works out the trajectory calculation. */ private Steerable<T> calculateTarget () { this.jumpTarget.position = jumpDescriptor.takeoffPosition; this.airborneTime = calculateAirborneTimeAndVelocity(jumpTarget.linearVelocity, jumpDescriptor, getActualLimiter() .getMaxLinearSpeed()); this.isJumpAchievable = airborneTime >= 0; return jumpTarget; }
/** Creates a {@code Hide} behavior for the specified owner, target and proximity. * @param owner the owner of this behavior * @param target the target of this behavior * @param proximity the proximity to find nearby obstacles */ public Hide (Steerable<T> owner, Location<T> target, Proximity<T> proximity) { super(owner, target); this.proximity = proximity; this.bestHidingSpot = newVector(owner); this.toObstacle = null; // Set to null since we'll reuse steering.linear for this vector }
/** Creates a {@code Wander} behavior for the specified owner. * @param owner the owner of this behavior. */ public Wander (Steerable<T> owner) { super(owner); this.internalTargetPosition = newVector(owner); this.wanderCenter = newVector(owner); }
@Override public boolean execute() { final Array<Object> args = cma.getArguments(); Player player = (Player) args.get(0); float x = (float) args.get(3); float y = (float) args.get(4); GameEntity gameEntity = player.mainEntity; if(gameEntity.getCurrentState() != MainShipState.Damaged) { boolean hasTarget = false; Array<Body> aabbFound = Box2dUtils.queryAABBInput(x, y); if(aabbFound.size > 0) { for(Body b : aabbFound){ GameEntity abbEntity = (GameEntity) b.getUserData(); GameEntityType entityType = Mappers.gameEntityType.get(abbEntity.entity).type; if(entityType == GameEntityType.Enemy || entityType == GameEntityType.Scenario) { LockOnComponent lockOnComponent = Mappers.lockOn.get(gameEntity.entity); if(lockOnComponent == null) lockOnComponent = gameEntity.addComponent(LockOnComponent.class); lockOnComponent.origin = gameEntity; lockOnComponent.target = abbEntity; gameEntity.changeState(MainShipState.LockOn); hasTarget = true; break; } } } if(!hasTarget){ SteeringBehaviorComponent steeringBC = Mappers.steeringBehavior.get(gameEntity.entity); Steerable steerableC = Mappers.steerable.get(gameEntity.entity); Arrive<Vector2> arrive = (Arrive<Vector2>) gameEntity.getBehavior(Arrive.class); if (arrive == null) { SteerLocation location = new SteerLocation(); arrive = new Arrive<Vector2>(steerableC, location); arrive.setArrivalTolerance(0.5f); arrive.setDecelerationRadius(10f); arrive.setTimeToTarget(0.005f); } arrive.setOwner(steerableC); gameEntity.cacheBehavior(steeringBC.behavior); steeringBC.behavior = arrive; arrive.getTarget().getPosition().set(x, y); gameEntity.changeState(MainShipState.Ready); } } return true; }
@Override public Steerable<T> getOwner () { return owner; }
@Override public void setOwner (Steerable<T> owner) { this.owner = owner; }
/** Returns the the agents that represent potential neighbors. */ public Iterable<? extends Steerable<T>> getAgents () { return agents; }
/** Sets the agents that represent potential neighbors. */ public void setAgents (Iterable<Steerable<T>> agents) { this.agents = agents; }
/** Creates a {@code RadiusProximity} for the specified owner, agents and radius. * @param owner the owner of this proximity * @param agents the agents * @param radius the radius of the cone area */ public RadiusProximity (Steerable<T> owner, Iterable<? extends Steerable<T>> agents, float radius) { super(owner, agents); this.radius = radius; this.lastTime = 0; }
/** Creates a {@code InfiniteProximity} for the specified owner and list of agents. * @param owner the owner of this proximity * @param agents the list of agents */ public InfiniteProximity (Steerable<T> owner, Iterable<? extends Steerable<T>> agents) { super(owner, agents); }
/** Returns the first agent. */ public Steerable<T> getAgentA () { return agentA; }
/** Sets the first agent. * @return this behavior for chaining. */ public Interpose<T> setAgentA (Steerable<T> agentA) { this.agentA = agentA; return this; }
/** Returns the second agent. */ public Steerable<T> getAgentB () { return agentB; }
/** Sets the second agent. * @return this behavior for chaining. */ public Interpose<T> setAgentB (Steerable<T> agentB) { this.agentB = agentB; return this; }
@Override public Interpose<T> setOwner (Steerable<T> owner) { this.owner = owner; return this; }
/** Creates a {@code MatchVelocity} behavior for the given owner. No target is set. The maxLinearAcceleration is set to 100. The * timeToTarget is set to 0.1 seconds. * @param owner the owner of this behavior. */ public MatchVelocity (Steerable<T> owner) { this(owner, null); }
/** Creates a {@code MatchVelocity} behavior for the given owner and target. The timeToTarget is set to 0.1 seconds. * @param owner the owner of this behavior * @param target the target of this behavior. */ public MatchVelocity (Steerable<T> owner, Steerable<T> target) { this(owner, target, 0.1f); }
/** Creates a {@code MatchVelocity} behavior for the given owner, target and timeToTarget. * @param owner the owner of this behavior * @param target the target of this behavior * @param timeToTarget the time over which to achieve target speed. */ public MatchVelocity (Steerable<T> owner, Steerable<T> target, float timeToTarget) { super(owner); this.target = target; this.timeToTarget = timeToTarget; }
/** Returns the target whose velocity should be matched. */ public Steerable<T> getTarget () { return target; }
/** Sets the target whose velocity should be matched. * @param target the target to set * @return this behavior for chaining. */ public MatchVelocity<T> setTarget (Steerable<T> target) { this.target = target; return this; }