Backported animcontroller-overhaul
This commit is contained in:
@@ -41,7 +41,7 @@ namespace Barotrauma
|
||||
|
||||
public Vector2 Velocity
|
||||
{
|
||||
get { return Character.AnimController.RefLimb.LinearVelocity; }
|
||||
get { return Character.AnimController.Collider.LinearVelocity; }
|
||||
}
|
||||
|
||||
public AiState State
|
||||
|
||||
@@ -71,36 +71,21 @@ namespace Barotrauma
|
||||
|
||||
steeringManager.Update(moveSpeed);
|
||||
|
||||
Character.AnimController.IgnorePlatforms = Character.AnimController.TargetMovement.Y < -0.5f &&
|
||||
bool ignorePlatforms = Character.AnimController.TargetMovement.Y < -0.5f &&
|
||||
(-Character.AnimController.TargetMovement.Y > Math.Abs(Character.AnimController.TargetMovement.X));
|
||||
|
||||
var currPath = (steeringManager as IndoorsSteeringManager).CurrentPath;
|
||||
if (currPath != null && currPath.CurrentNode != null)
|
||||
{
|
||||
if (currPath.CurrentNode.WorldPosition.Y < Character.WorldPosition.Y - 200)
|
||||
if (currPath.CurrentNode.SimPosition.Y < Character.AnimController.GetColliderBottom().Y)
|
||||
{
|
||||
Character.AnimController.IgnorePlatforms = true;
|
||||
}
|
||||
|
||||
if (Character.AnimController.Stairs != null)
|
||||
{
|
||||
float yDiff = currPath.CurrentNode.WorldPosition.Y - Character.WorldPosition.Y;
|
||||
|
||||
if (Math.Abs(yDiff)>10.0f)
|
||||
{
|
||||
int dir = Math.Sign(yDiff);
|
||||
|
||||
float movement = Character.AnimController.Stairs.StairDirection == Direction.Right ?
|
||||
dir * Character.AnimController.TargetMovement.Length() : -dir * Character.AnimController.TargetMovement.Length();
|
||||
|
||||
Character.AnimController.TargetMovement = new Vector2(movement, 0.0f);
|
||||
}
|
||||
ignorePlatforms = true;
|
||||
}
|
||||
}
|
||||
|
||||
Character.AnimController.IgnorePlatforms = ignorePlatforms;
|
||||
(Character.AnimController as HumanoidAnimController).Crouching = false;
|
||||
|
||||
|
||||
if (!Character.AnimController.InWater)
|
||||
{
|
||||
Character.AnimController.TargetMovement = new Vector2(
|
||||
|
||||
@@ -88,6 +88,15 @@ namespace Barotrauma
|
||||
|
||||
Vector2 diff = DiffToCurrentNode();
|
||||
|
||||
var collider = character.AnimController.Collider;
|
||||
//if not in water and the waypoint is between the top and bottom of the collider, no need to move vertically
|
||||
if (!character.AnimController.InWater &&
|
||||
character.AnimController.Anim != AnimController.Animation.Climbing &&
|
||||
diff.Y < collider.height / 2 + collider.radius)
|
||||
{
|
||||
diff.Y = 0.0f;
|
||||
}
|
||||
|
||||
if (diff == Vector2.Zero) return -host.Steering;
|
||||
|
||||
return Vector2.Normalize(diff) * speed;
|
||||
@@ -95,7 +104,7 @@ namespace Barotrauma
|
||||
|
||||
private Vector2 DiffToCurrentNode()
|
||||
{
|
||||
if (currentPath == null || currentPath.Finished) return Vector2.Zero;
|
||||
if (currentPath == null || currentPath.Finished || currentPath.Unreachable) return Vector2.Zero;
|
||||
|
||||
if (currentPath.Finished)
|
||||
{
|
||||
@@ -111,7 +120,7 @@ namespace Barotrauma
|
||||
if (canOpenDoors && !character.LockHands) CheckDoorsInPath();
|
||||
|
||||
float allowedDistance = character.AnimController.InWater ? 1.0f : 0.6f;
|
||||
if (currentPath.CurrentNode!=null && currentPath.CurrentNode.SimPosition.Y > character.SimPosition.Y+1.0f) allowedDistance*=0.5f;
|
||||
//if (currentPath.CurrentNode!=null && currentPath.CurrentNode.SimPosition.Y > character.SimPosition.Y+1.0f) allowedDistance*=0.5f;
|
||||
|
||||
Vector2 pos = host.SimPosition;
|
||||
|
||||
@@ -139,7 +148,15 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
currentPath.CheckProgress(pos, allowedDistance);
|
||||
var collider = character.AnimController.Collider;
|
||||
|
||||
Vector2 colliderBottom = character.AnimController.GetColliderBottom();
|
||||
if (Math.Abs(collider.SimPosition.X - currentPath.CurrentNode.SimPosition.X) < collider.radius*2 &&
|
||||
currentPath.CurrentNode.SimPosition.Y > colliderBottom.Y &&
|
||||
currentPath.CurrentNode.SimPosition.Y < colliderBottom.Y + collider.height + collider.radius*2)
|
||||
{
|
||||
currentPath.SkipToNextNode();
|
||||
}
|
||||
|
||||
if (currentPath.CurrentNode == null) return Vector2.Zero;
|
||||
|
||||
@@ -147,20 +164,31 @@ namespace Barotrauma
|
||||
|
||||
if (character.AnimController.Anim == AnimController.Animation.Climbing)
|
||||
{
|
||||
float x = currentPath.CurrentNode.SimPosition.X - pos.X;
|
||||
float y = (currentPath.CurrentNode.SimPosition.Y) - pos.Y;
|
||||
Vector2 diff = currentPath.CurrentNode.SimPosition - pos;
|
||||
|
||||
if (Math.Abs(x) < Math.Abs(y) * 10.0f)
|
||||
if (currentPath.CurrentNode.Ladders != null)
|
||||
{
|
||||
x = 0.0f;
|
||||
}
|
||||
else if (character.AnimController.LowestLimb != null && hull != null)
|
||||
{
|
||||
if (character.AnimController.LowestLimb.Position.Y < hull.Rect.Y - hull.Rect.Height + 10.0f) x = 0.0f;
|
||||
//climbing ladders -> don't move horizontally
|
||||
diff.X = 0.0f;
|
||||
|
||||
//at the same height as the waypoint
|
||||
if (currentPath.CurrentNode.SimPosition.Y > colliderBottom.Y &&
|
||||
currentPath.CurrentNode.SimPosition.Y < colliderBottom.Y + collider.height + collider.radius * 2)
|
||||
{
|
||||
float heightFromFloor = character.AnimController.GetColliderBottom().Y - character.AnimController.FloorY;
|
||||
|
||||
//we can safely skip to the next waypoint if the character is at a safe height above the floor,
|
||||
//or if the next waypoint in the path is also on ladders
|
||||
if ((heightFromFloor > 0.0f && heightFromFloor < collider.height) ||
|
||||
(currentPath.NextNode != null && currentPath.NextNode.Ladders != null))
|
||||
{
|
||||
currentPath.SkipToNextNode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
character.AnimController.IgnorePlatforms = false;
|
||||
return new Vector2(x,y);
|
||||
return diff;
|
||||
}
|
||||
|
||||
return currentPath.CurrentNode.SimPosition - pos;
|
||||
|
||||
@@ -90,11 +90,12 @@ namespace Barotrauma
|
||||
|
||||
escapeObjective.TryComplete(deltaTime);
|
||||
|
||||
if (Vector2.Distance(character.SimPosition, enemy.SimPosition) < 3.0f)
|
||||
{
|
||||
character.AIController.SteeringManager.SteeringManual(deltaTime, (character.SimPosition - enemy.SimPosition)*0.1f);
|
||||
coolDownTimer = CoolDown;
|
||||
}
|
||||
//if (Vector2.Distance(character.SimPosition, enemy.SimPosition) < 3.0f)
|
||||
//{
|
||||
// character.AIController.SteeringManager.SteeringManual(deltaTime,
|
||||
// new Vector2(Math.Sign(character.SimPosition.X - enemy.SimPosition.X), 0.0f));
|
||||
// coolDownTimer = CoolDown;
|
||||
//}
|
||||
}
|
||||
|
||||
public override bool IsCompleted()
|
||||
|
||||
@@ -168,8 +168,11 @@ namespace Barotrauma
|
||||
//if searching for a path inside the sub, make sure the waypoint is visible
|
||||
if (insideSubmarine)
|
||||
{
|
||||
var body = Submarine.CheckVisibility(start, node.Waypoint.SimPosition);
|
||||
if (body != null && body.UserData is Structure) continue;
|
||||
var body = Submarine.PickBody(
|
||||
start, node.Waypoint.SimPosition, null,
|
||||
Physics.CollisionWall | Physics.CollisionLevel | Physics.CollisionStairs | Physics.CollisionPlatform);
|
||||
|
||||
if (body != null && body.UserData is Structure && !((Structure)body.UserData).IsPlatform) continue;
|
||||
}
|
||||
|
||||
closestDist = dist;
|
||||
|
||||
@@ -62,6 +62,13 @@ namespace Barotrauma
|
||||
|
||||
public virtual void Update(float speed = 1.0f)
|
||||
{
|
||||
if (steering == Vector2.Zero || !MathUtils.IsValid(steering))
|
||||
{
|
||||
steering = Vector2.Zero;
|
||||
host.Steering = Vector2.Zero;
|
||||
return;
|
||||
}
|
||||
|
||||
float steeringSpeed = steering.Length();
|
||||
if (steeringSpeed>speed)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user