Behavior Canceling & Grouping
Behaviors are now grouped, behaviors within a group can cancel execution of the rest of the group
This commit is contained in:
parent
c24c155673
commit
fc94531566
35 changed files with 613 additions and 190 deletions
|
|
@ -14,12 +14,16 @@ public class Locomotion : AgentBehavior
|
|||
private Thruster _thrust;
|
||||
private Turning _turning;
|
||||
private VelocityLimit _velocityLimit;
|
||||
private int _thrustAxis;
|
||||
private int _turningAxis;
|
||||
|
||||
public Locomotion(GameContext context, Entity entity, ControllerData controllerData) : base(context, entity, controllerData)
|
||||
{
|
||||
_velocityLimit = Entity.GetBehaviors<VelocityLimit>().FirstOrDefault();
|
||||
_thrust = Entity.Axes.Keys.FirstOrDefault(x => x is Thruster) as Thruster;
|
||||
_turning = Entity.Axes.Keys.FirstOrDefault(x => x is Turning) as Turning;
|
||||
_thrust = Entity.GetBehaviors<Thruster>().FirstOrDefault();
|
||||
_turning = Entity.GetBehaviors<Turning>().FirstOrDefault();
|
||||
_thrustAxis = Entity.GetAxis<Thruster>();
|
||||
_turningAxis = Entity.GetAxis<Turning>();
|
||||
}
|
||||
|
||||
public override void Update(float delta)
|
||||
|
|
@ -40,15 +44,15 @@ public class Locomotion : AgentBehavior
|
|||
{
|
||||
float2 tangential = Entity.Velocity - dot(normalize(diff), normalize(Entity.Velocity)) * Entity.Velocity;
|
||||
float2 adjustedDirection = normalize(diff) - tangential * TangentSensitivity;
|
||||
Entity.Axes[_turning] = TurningInput(adjustedDirection);
|
||||
Entity.Axes[_thrust] = 1;
|
||||
Entity.Axes[_turningAxis].Value = TurningInput(adjustedDirection);
|
||||
Entity.Axes[_thrustAxis].Value = 1;
|
||||
}
|
||||
// We have plenty of space, use exact maneuvering
|
||||
else
|
||||
{
|
||||
var deltaV = desiredVelocity - Entity.Velocity;
|
||||
Entity.Axes[_turning] = TurningInput(deltaV);
|
||||
Entity.Axes[_thrust] = ThrustInput(deltaV);
|
||||
Entity.Axes[_turningAxis].Value = TurningInput(deltaV);
|
||||
Entity.Axes[_thrustAxis].Value = ThrustInput(deltaV);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,14 +12,18 @@ public class VelocityMatch : AgentBehavior
|
|||
private Thruster _thrust;
|
||||
private Turning _turning;
|
||||
private const float TargetThreshold = .1f;
|
||||
private int _thrustAxis;
|
||||
private int _turningAxis;
|
||||
|
||||
private GameContext _context;
|
||||
|
||||
public VelocityMatch(GameContext context, Entity entity, ControllerData controllerData) : base(context, entity, controllerData)
|
||||
{
|
||||
_context = context;
|
||||
_thrust = Entity.Axes.Keys.FirstOrDefault(x => x is Thruster) as Thruster;
|
||||
_turning = Entity.Axes.Keys.FirstOrDefault(x => x is Turning) as Turning;
|
||||
_thrust = Entity.GetBehaviors<Thruster>().FirstOrDefault();
|
||||
_turning = Entity.GetBehaviors<Turning>().FirstOrDefault();
|
||||
_thrustAxis = Entity.GetAxis<Thruster>();
|
||||
_turningAxis = Entity.GetAxis<Turning>();
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
|
|
@ -34,8 +38,8 @@ public class VelocityMatch : AgentBehavior
|
|||
var deltaV = TargetVelocity - Entity.Velocity;
|
||||
if(length(deltaV) < TargetThreshold)
|
||||
OnMatch?.Invoke();
|
||||
Entity.Axes[_turning] = TurningInput(deltaV);
|
||||
Entity.Axes[_thrust] = ThrustInput(deltaV);
|
||||
Entity.Axes[_turningAxis].Value = TurningInput(deltaV);
|
||||
Entity.Axes[_thrustAxis].Value = ThrustInput(deltaV);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue