1 using FarseerPhysics.Dynamics;
2 using Microsoft.Xna.Framework;
18 private float lastRayCastTime;
20 private bool avoidRayCastHit;
26 private float wanderAngle;
30 get {
return wanderAngle; }
31 set { wanderAngle = value; }
38 wanderAngle = Rand.Range(0.0f, MathHelper.TwoPi);
46 public void SteeringWander(
float weight = 1,
bool avoidWanderingOutsideLevel =
false)
51 public void SteeringAvoid(
float deltaTime,
float lookAheadDistance,
float weight = 1)
58 if (MathUtils.IsValid(velocity))
80 public virtual void Update(
float speed)
88 if (
steering.LengthSquared() > speed * speed)
104 if (targetVel.LengthSquared() < 0.00001f) {
return Vector2.Zero; }
106 targetVel = Vector2.Normalize(targetVel) * weight;
129 Vector2 displacement =
new Vector2(
130 (
float)Math.Cos(wanderAngle),
131 (
float)Math.Sin(wanderAngle));
134 float angleChange = 1.5f;
136 wanderAngle += Rand.Range(0.0f, 1.0f) * angleChange - angleChange * 0.5f;
138 Vector2 newSteering = circleCenter + displacement;
139 if (avoidWanderingOutsideLevel &&
Level.
Loaded !=
null)
141 float margin = 5000.0f;
154 float steeringSpeed = (newSteering +
host.
Steering).Length();
155 if (steeringSpeed > weight)
157 newSteering = Vector2.Normalize(newSteering) * weight;
164 protected virtual Vector2
DoSteeringAvoid(
float deltaTime,
float lookAheadDistance,
float weight, Vector2? heading =
null)
171 float maxDistance = lookAheadDistance;
174 avoidRayCastHit =
false;
176 lastRayCastTime = (float)Timing.TotalTime;
178 if (closestBody !=
null)
180 avoidRayCastHit =
true;
190 if (
AvoidDir.LengthSquared() < 0.0001f) {
return Vector2.Zero; }
193 if (!avoidRayCastHit)
199 float dist = diff.Length();
202 float dot = MathHelper.Clamp(Vector2.Dot(diff / dist,
host.
Steering), 0.0f, 1.0f);
203 if (dot < 0) {
return Vector2.Zero; }
205 return AvoidDir * dot * weight * MathHelper.Clamp(1.0f - dist / lookAheadDistance, 0.0f, 1.0f);
Affliction GetAfflictionOfType(Identifier afflictionType, bool allowLimbAfflictions=true)
CharacterHealth CharacterHealth
virtual Vector2 DoSteeringWander(float weight, bool avoidWanderingOutsideLevel)
const float CircleDistance
void SteeringManual(float deltaTime, Vector2 velocity)
void SteeringSeek(Vector2 targetSimPos, float weight=1)
void SteeringWander(float weight=1, bool avoidWanderingOutsideLevel=false)
virtual Vector2 DoSteeringAvoid(float deltaTime, float lookAheadDistance, float weight, Vector2? heading=null)
void SteeringAvoid(float deltaTime, float lookAheadDistance, float weight=1)
const float RayCastInterval
virtual void Update(float speed)
Update speed for the steering. Should normally match the characters current animation speed.
SteeringManager(ISteerable host)
Vector2 AvoidRayCastHitPosition
virtual Vector2 DoSteeringSeek(Vector2 target, float weight)
Vector2 AvoidLookAheadPos
static Vector2 LastPickedNormal
static Body CheckVisibility(Vector2 rayStart, Vector2 rayEnd, bool ignoreLevel=false, bool ignoreSubs=false, bool ignoreSensors=true, bool ignoreDisabledWalls=true, bool ignoreBranches=true, Predicate< Fixture > blocksVisibilityPredicate=null)
Check visibility between two points (in sim units).
static Vector2 LastPickedPosition