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
@@ -1,5 +1,6 @@
using Lidgren.Network;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace Subsurface
{
@@ -21,7 +22,7 @@ namespace Subsurface
set { Character.AnimController.TargetMovement = value; }
}
public Vector2 Position
public Vector2 SimPosition
{
get { return Character.AnimController.Limbs[0].SimPosition; }
}
@@ -44,6 +45,11 @@ namespace Subsurface
steeringManager = new SteeringManager(this);
}
public virtual void DebugDraw(SpriteBatch spriteBatch)
{
}
public virtual void OnAttacked(IDamageable attacker, float amount) { }
public virtual void SelectTarget(AITarget target) { }
@@ -6,6 +6,7 @@ using FarseerPhysics;
using Lidgren.Network;
using Microsoft.Xna.Framework;
using FarseerPhysics.Dynamics;
using Microsoft.Xna.Framework.Graphics;
namespace Subsurface
{
@@ -264,6 +265,9 @@ namespace Subsurface
public override void OnAttacked(IDamageable attacker, float amount)
{
updateTargetsTimer = Math.Min(updateTargetsTimer, 0.1f);
coolDownTimer *= 0.1f;
if (attacker==null || attacker.AiTarget==null) return;
AITargetMemory targetMemory = FindTargetMemory(attacker.AiTarget);
targetMemory.Priority += amount;
@@ -319,7 +323,7 @@ namespace Subsurface
Vector2.Normalize(attackPosition - limb.SimPosition));
}
steeringManager.SteeringSeek(attackPosition + (limb.SimPosition-Position), 5.0f);
steeringManager.SteeringSeek(attackPosition + (limb.SimPosition-SimPosition), 5.0f);
break;
default:
@@ -329,6 +333,7 @@ namespace Subsurface
if (attackTimer >= limb.attack.Duration)
{
wallAttackPos = Vector2.Zero;
attackTimer = 0.0f;
if (Vector2.Distance(limb.SimPosition, attackPosition)<5.0) coolDownTimer = attackCoolDown;
@@ -477,6 +482,32 @@ namespace Subsurface
}
}
public override void DebugDraw(SpriteBatch spriteBatch)
{
if (Character.IsDead) return;
Vector2 pos = Character.Position;
pos.Y = -pos.Y;
if (selectedAiTarget!=null)
{
GUI.DrawLine(spriteBatch, pos, ConvertUnits.ToDisplayUnits(new Vector2(selectedAiTarget.Position.X, -selectedAiTarget.Position.Y)), Color.Red);
if (wallAttackPos!=Vector2.Zero)
{
GUI.DrawRectangle(spriteBatch, ConvertUnits.ToDisplayUnits(new Vector2(wallAttackPos.X, -wallAttackPos.Y)) - new Vector2(10.0f, 10.0f), new Vector2(20.0f, 20.0f), Color.Red, false);
}
spriteBatch.DrawString(GUI.Font, targetValue.ToString(), pos - Vector2.UnitY*20.0f, Color.Red);
}
spriteBatch.DrawString(GUI.Font, targetValue.ToString(), pos - Vector2.UnitY * 80.0f, Color.Red);
spriteBatch.DrawString(GUI.Font, "updatetargets: "+updateTargetsTimer, pos - Vector2.UnitY * 100.0f, Color.Red);
spriteBatch.DrawString(GUI.Font, "cooldown: " + coolDownTimer, pos - Vector2.UnitY * 120.0f, Color.Red);
}
public override void FillNetworkData(NetOutgoingMessage message)
{
message.Write((byte)state);
@@ -16,7 +16,7 @@ namespace Subsurface
get;
}
Vector2 Position
Vector2 SimPosition
{
get;
}
@@ -63,7 +63,7 @@ namespace Subsurface
private Vector2 DoSteeringSeek(Vector2 target, float speed = 1.0f)
{
Vector2 targetVel = target - host.Position;
Vector2 targetVel = target - host.SimPosition;
if (targetVel.LengthSquared() < 0.00001f) return Vector2.Zero;
@@ -111,12 +111,12 @@ namespace Subsurface
float maxDistance = 2.0f;
Vector2 ahead = host.Position + Vector2.Normalize(host.Steering)*maxDistance;
Vector2 ahead = host.SimPosition + Vector2.Normalize(host.Steering)*maxDistance;
if (rayCastTimer <= 0.0f)
{
rayCastTimer = RayCastInterval;
Body closestBody = Submarine.CheckVisibility(host.Position, ahead);
Body closestBody = Submarine.CheckVisibility(host.SimPosition, ahead);
if (closestBody == null)
{
avoidSteering = Vector2.Zero;
+33 -10
View File
@@ -5,32 +5,55 @@ namespace Subsurface
{
class SteeringPath
{
private Queue<WayPoint> nodes;
WayPoint currentNode;
private List<WayPoint> nodes;
int currentIndex;
public SteeringPath()
{
nodes = new Queue<WayPoint>();
nodes = new List<WayPoint>();
}
public void AddNode(WayPoint node)
{
if (node == null) return;
nodes.Enqueue(node);
nodes.Add(node);
}
public WayPoint CurrentNode
{
get { return currentNode; }
get
{
if (currentIndex < 0 || currentIndex > nodes.Count - 1) return null;
return nodes[currentIndex];
}
}
public WayPoint GetNode(Vector2 pos, float minDistance = 0.1f)
public List<WayPoint> Nodes
{
if (nodes.Count == 0) return null;
if (currentNode == null || Vector2.Distance(pos, currentNode.SimPosition) < minDistance) currentNode = nodes.Dequeue();
get { return nodes; }
}
return currentNode;
public WayPoint NextNode
{
get
{
if (currentIndex+1 < 0 || currentIndex+1 > nodes.Count - 1) return null;
return nodes[currentIndex+1];
}
}
public void SkipToNextNode()
{
currentIndex++;
}
public WayPoint CheckProgress(Vector2 pos, float minSimDistance = 0.1f)
{
if (nodes.Count == 0 || currentIndex>nodes.Count-1) return null;
if (Vector2.Distance(pos, nodes[currentIndex].SimPosition) < minSimDistance) currentIndex++;
return CurrentNode;
}
public void ClearPath()