Autopilot tweaking
This commit is contained in:
@@ -33,6 +33,8 @@ namespace Barotrauma.Items.Components
|
|||||||
|
|
||||||
private float autopilotRayCastTimer;
|
private float autopilotRayCastTimer;
|
||||||
|
|
||||||
|
private Vector2 avoidStrength;
|
||||||
|
|
||||||
private float neutralBallastLevel;
|
private float neutralBallastLevel;
|
||||||
|
|
||||||
public Vector2? TargetPosition;
|
public Vector2? TargetPosition;
|
||||||
@@ -236,7 +238,7 @@ namespace Barotrauma.Items.Components
|
|||||||
|
|
||||||
float dist = Vector2.Distance(cornerPos, steeringPath.NextNode.SimPosition);
|
float dist = Vector2.Distance(cornerPos, steeringPath.NextNode.SimPosition);
|
||||||
|
|
||||||
if (Submarine.PickBody(cornerPos, cornerPos + diff*dist, null, Physics.CollisionLevel) == null) continue;
|
if (Submarine.PickBody(cornerPos, cornerPos + diff * dist, null, Physics.CollisionLevel) == null) continue;
|
||||||
|
|
||||||
nextVisible = false;
|
nextVisible = false;
|
||||||
x = 2;
|
x = 2;
|
||||||
@@ -257,7 +259,7 @@ namespace Barotrauma.Items.Components
|
|||||||
float avoidRadius = Math.Max(item.Submarine.Borders.Width, item.Submarine.Borders.Height) * 2.0f;
|
float avoidRadius = Math.Max(item.Submarine.Borders.Width, item.Submarine.Borders.Height) * 2.0f;
|
||||||
avoidRadius = Math.Max(avoidRadius, 2000.0f);
|
avoidRadius = Math.Max(avoidRadius, 2000.0f);
|
||||||
|
|
||||||
Vector2 avoidStrength = Vector2.Zero;
|
Vector2 newAvoidStrength = Vector2.Zero;
|
||||||
|
|
||||||
//steer away from nearby walls
|
//steer away from nearby walls
|
||||||
var closeCells = Level.Loaded.GetCells(item.Submarine.WorldPosition, 4);
|
var closeCells = Level.Loaded.GetCells(item.Submarine.WorldPosition, 4);
|
||||||
@@ -274,18 +276,20 @@ namespace Barotrauma.Items.Components
|
|||||||
if (diff.Length() > avoidRadius) continue;
|
if (diff.Length() > avoidRadius) continue;
|
||||||
|
|
||||||
float dot = item.Submarine.Velocity == Vector2.Zero ?
|
float dot = item.Submarine.Velocity == Vector2.Zero ?
|
||||||
0.0f : Vector2.Dot(Vector2.Normalize(item.Submarine.Velocity), -Vector2.Normalize(diff));
|
0.0f : Vector2.Dot(item.Submarine.Velocity, -Vector2.Normalize(diff));
|
||||||
|
|
||||||
//heading away from the wall -> ignore
|
//not heading towards the wall -> ignore
|
||||||
if (dot < 0) continue;
|
if (dot < 0.5) continue;
|
||||||
|
|
||||||
Vector2 change = (Vector2.Normalize(diff) * Math.Max((avoidRadius - diff.Length()), 0.0f)) / avoidRadius;
|
Vector2 change = (Vector2.Normalize(diff) * Math.Max((avoidRadius - diff.Length()), 0.0f)) / avoidRadius;
|
||||||
|
|
||||||
avoidStrength += change * dot;
|
newAvoidStrength += change * dot;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
avoidStrength = Vector2.Lerp(avoidStrength, newAvoidStrength, deltaTime * 10.0f);
|
||||||
|
|
||||||
targetVelocity += avoidStrength * 100.0f;
|
targetVelocity += avoidStrength * 100.0f;
|
||||||
|
|
||||||
//steer away from other subs
|
//steer away from other subs
|
||||||
|
|||||||
Reference in New Issue
Block a user