Better autopilot, guiframe tweaking, fixed ui scaling, aicontroller bugfixes, human walk/run anim uses HandIK

This commit is contained in:
Regalis
2015-10-06 21:18:36 +03:00
parent f13a48ef52
commit db7128a475
37 changed files with 533 additions and 383 deletions
@@ -172,6 +172,31 @@ namespace Subsurface.Items.Components
quest.RadarPosition, displayScale, center, (rect.Width * 0.55f));
}
}
if (!GameMain.DebugDraw) return;
var steering = item.GetComponent<Steering>();
if (steering == null || steering.SteeringPath == null) return;
Vector2 prevPos = Vector2.Zero;
foreach (WayPoint wp in steering.SteeringPath.Nodes)
{
Vector2 pos = (wp.Position - Submarine.Loaded.Position) * displayScale;
if (pos.Length() > radius) continue;
pos.Y = -pos.Y;
pos += center;
GUI.DrawRectangle(spriteBatch, new Rectangle((int)pos.X -3 / 2, (int)pos.Y - 3, 6, 6), (steering.SteeringPath.CurrentNode==wp) ? Color.LightGreen : Color.Green, false);
if (prevPos!=Vector2.Zero)
{
GUI.DrawLine(spriteBatch, pos, prevPos, Color.Green);
}
prevPos = pos;
}
}
private void DrawMarker(SpriteBatch spriteBatch, string label, Vector2 position, float scale, Vector2 center, float radius)
@@ -12,6 +12,8 @@ namespace Subsurface.Items.Components
{
class Steering : Powered
{
private const float AutopilotRayCastInterval = 5.0f;
private Vector2 currVelocity;
private Vector2 targetVelocity;
@@ -24,6 +26,8 @@ namespace Subsurface.Items.Components
private float networkUpdateTimer;
private bool valueChanged;
private float autopilotRayCastTimer;
bool AutoPilot
{
get { return autoPilot; }
@@ -37,7 +41,7 @@ namespace Subsurface.Items.Components
{
if (pathFinder==null) pathFinder = new PathFinder(WayPoint.WayPointList, false);
steeringPath = pathFinder.FindPath(
ConvertUnits.ToSimUnits(Level.Loaded.Position),
ConvertUnits.ToSimUnits(Submarine.Loaded.Position),
ConvertUnits.ToSimUnits(Level.Loaded.EndPosition));
}
}
@@ -59,6 +63,11 @@ namespace Subsurface.Items.Components
get { return targetVelocity; }
}
public SteeringPath SteeringPath
{
get { return steeringPath; }
}
public Steering(Item item, XElement element)
: base(item, element)
{
@@ -81,21 +90,7 @@ namespace Subsurface.Items.Components
// ConvertUnits.ToSimUnits(Level.Loaded.EndPosition));
//}
steeringPath.GetNode(Vector2.Zero, 20.0f);
if (steeringPath.CurrentNode!=null)
{
float prediction = 10.0f;
Vector2 futurePosition = Submarine.Loaded.Speed * prediction;
Vector2 targetSpeed = (steeringPath.CurrentNode.Position - futurePosition);
//float dist = targetSpeed.Length();
targetSpeed = Vector2.Normalize(targetSpeed);
TargetVelocity = targetSpeed*100.0f;
}
UpdateAutoPilot(deltaTime);
}
else if (valueChanged)
{
@@ -160,6 +155,51 @@ namespace Subsurface.Items.Components
}
}
private void UpdateAutoPilot(float deltaTime)
{
autopilotRayCastTimer -= deltaTime;
steeringPath.CheckProgress(ConvertUnits.ToSimUnits(Submarine.Loaded.Position), 10.0f);
if (autopilotRayCastTimer<=0.0f && steeringPath.NextNode != null)
{
Vector2 diff = steeringPath.NextNode.Position - Submarine.Loaded.Position;
bool nextVisible = true;
for (int x = -1; x < 2; x += 2)
{
for (int y = -1; y < 2; y += 2)
{
Vector2 cornerPos =
new Vector2(Submarine.Borders.Width * x, Submarine.Borders.Height * y) / 2.0f;
cornerPos = ConvertUnits.ToSimUnits(cornerPos*1.2f);
if (Submarine.PickBody(cornerPos, cornerPos + diff, null, Physics.CollisionLevel) == null) continue;
nextVisible = false;
x = 2;
y = 2;
}
}
if (nextVisible) steeringPath.SkipToNextNode();
autopilotRayCastTimer = AutopilotRayCastInterval;
}
if (steeringPath.CurrentNode != null)
{
float prediction = 5.0f;
Vector2 futurePosition = Submarine.Loaded.Speed * prediction;
Vector2 targetSpeed = ((steeringPath.CurrentNode.Position - Submarine.Loaded.Position) - futurePosition);
targetSpeed = Vector2.Normalize(targetSpeed);
TargetVelocity = targetSpeed * 100.0f;
}
}
public override void ReceiveSignal(string signal, Connection connection, Item sender, float power=0.0f)
{
if (connection.Name == "velocity_in")