Simpler anim logic for off-screen characters (all limbs except refLimb are hidden)

This commit is contained in:
Regalis
2015-09-29 20:06:15 +03:00
parent 45178e745b
commit 655862fc0f
10 changed files with 116 additions and 36 deletions

View File

@@ -601,11 +601,10 @@ namespace Subsurface
/// </summary>
public void ControlLocalPlayer(float deltaTime, Camera cam, bool moveCam = true)
{
//if (isDead)
//{
// return;
//}
if (PlayerInput.KeyHit(Keys.U))
{
AnimController.SimplePhysicsEnabled = !AnimController.SimplePhysicsEnabled;
}
Limb head = AnimController.GetLimb(LimbType.Head);
@@ -747,6 +746,8 @@ namespace Subsurface
public virtual void Update(Camera cam, float deltaTime)
{
AnimController.SimplePhysicsEnabled = (Character.controlled!=this && Vector2.Distance(cam.WorldViewCenter, Position)>2000.0f);
if (isDead) return;
if (PressureProtection==0.0f &&

View File

@@ -4,6 +4,7 @@ using System.Xml.Linq;
using FarseerPhysics;
using FarseerPhysics.Dynamics.Joints;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
namespace Subsurface
{
@@ -48,6 +49,11 @@ namespace Subsurface
public override void UpdateAnim(float deltaTime)
{
if (PlayerInput.KeyHit(Keys.I))
{
SimplePhysicsEnabled = !SimplePhysicsEnabled;
}
if (character.IsDead)
{
UpdateDying(deltaTime);
@@ -68,6 +74,10 @@ namespace Subsurface
stunTimer -= deltaTime;
return;
}
else if (SimplePhysicsEnabled)
{
UpdateSimpleAnim();
}
else
{
if (inWater)
@@ -80,7 +90,6 @@ namespace Subsurface
}
}
if (flip)
{
//targetDir = (movement.X > 0.0f) ? Direction.Right : Direction.Left;
@@ -208,6 +217,31 @@ namespace Subsurface
floorY = Limbs[0].SimPosition.Y;
}
}
void UpdateSimpleAnim()
{
movement = MathUtils.SmoothStep(movement, TargetMovement*swimSpeed, 1.0f);
if (movement == Vector2.Zero) return;
float movementAngle = MathUtils.VectorToAngle(movement) - MathHelper.PiOver2;
RefLimb.body.SmoothRotate(
(rotateTowardsMovement) ?
RefLimb.body.Rotation + MathUtils.GetShortestAngle(RefLimb.body.Rotation, movementAngle) :
HeadAngle*Dir);
RefLimb.pullJoint.Enabled = true;
RefLimb.pullJoint.WorldAnchorB =
RefLimb.SimPosition + movement * 0.1f;
RefLimb.body.SmoothRotate(0.0f);
foreach (Limb l in Limbs)
{
if (l == RefLimb) continue;
l.body.SetTransform(RefLimb.SimPosition, RefLimb.Rotation);
}
}
void UpdateWalkAnim(float deltaTime)
{

View File

@@ -30,8 +30,8 @@ namespace Subsurface
public override void UpdateAnim(float deltaTime)
{
if (character.IsDead) return;
if (character.IsDead) return;
Vector2 colliderPos = GetLimb(LimbType.Torso).SimPosition;
//if (inWater) stairs = null;
@@ -136,6 +136,15 @@ namespace Subsurface
return;
}
if (TargetDir != dir) Flip();
if (SimplePhysicsEnabled)
{
UpdateStandingSimple();
return;
}
switch (Anim)
{
case Animation.Climbing:
@@ -152,7 +161,6 @@ namespace Subsurface
break;
}
if (TargetDir != dir) Flip();
foreach (Limb limb in Limbs)
{
@@ -389,6 +397,29 @@ namespace Subsurface
}
void UpdateStandingSimple()
{
movement = MathUtils.SmoothStep(movement, TargetMovement, movementLerp);
if (inWater && movement != Vector2.Zero)
{
movement = Vector2.Normalize(movement);
}
RefLimb.pullJoint.Enabled = true;
RefLimb.pullJoint.WorldAnchorB =
RefLimb.SimPosition + movement*0.15f;
RefLimb.body.SmoothRotate(0.0f);
foreach (Limb l in Limbs)
{
if (l==RefLimb) continue;
l.body.SetTransform(RefLimb.SimPosition, RefLimb.Rotation);
}
//new Vector2(movement.X, floorY + HeadPosition), 0.5f);
}
void UpdateSwimming()
{
IgnorePlatforms = true;

View File

@@ -22,7 +22,9 @@ namespace Subsurface
private Dictionary<LimbType, Limb> limbDictionary;
public RevoluteJoint[] limbJoints;
Character character;
private bool simplePhysicsEnabled;
private Character character;
private Limb lowestLimb;
@@ -76,6 +78,29 @@ namespace Subsurface
private set;
}
public bool SimplePhysicsEnabled
{
get { return simplePhysicsEnabled; }
set
{
if (value == simplePhysicsEnabled) return;
simplePhysicsEnabled = value;
foreach (Limb limb in Limbs)
{
limb.body.Enabled = !simplePhysicsEnabled;
}
foreach (RevoluteJoint joint in limbJoints)
{
joint.Enabled = !simplePhysicsEnabled;
}
refLimb.body.Enabled = true;
}
}
public Vector2 TargetMovement
{
get
@@ -473,11 +498,11 @@ namespace Subsurface
}
}
public static void UpdateAll(float deltaTime)
public static void UpdateAll(Camera cam, float deltaTime)
{
foreach (Ragdoll r in list)
{
r.Update(deltaTime);
r.Update(cam, deltaTime);
}
}
@@ -491,10 +516,12 @@ namespace Subsurface
currentHull);
}
public void Update(float deltaTime)
public void Update(Camera cam, float deltaTime)
{
UpdateNetplayerPosition();
Vector2 flowForce = Vector2.Zero;
FindLowestLimb();
@@ -537,8 +564,7 @@ namespace Subsurface
limb.inWater = true;
}
else if (limbHull.Volume > 0.0f && Submarine.RectContains(limbHull.Rect, limbPosition))
{
{
if (limbPosition.Y < limbHull.Surface)
{
limb.inWater = true;

View File

@@ -18,10 +18,7 @@ namespace Subsurface
public override Vector2 RadarPosition
{
get
{
return monster.Position;
}
get { return monster.Position; }
}
public MonsterQuest(XElement element)
@@ -34,7 +31,7 @@ namespace Subsurface
{
Vector2 position = level.PositionsOfInterest[Rand.Int(level.PositionsOfInterest.Count, false)];
monster = new Character(monsterFile, ConvertUnits.ToSimUnits(position+level.Position));
monster = new AICharacter(monsterFile, ConvertUnits.ToSimUnits(position+level.Position));
}
public override void End()

View File

@@ -206,7 +206,7 @@ namespace Subsurface.Items.Components
if (item.CurrentHull != null)
{
//the sound can be heard from 20 000 display units away when everything running at 100%
item.CurrentHull.SoundRange += (coolingRate + fissionRate) * 100;
item.CurrentHull.SoundRange = (coolingRate + fissionRate) * 100;
}
UpdateGraph(deltaTime);

View File

@@ -728,19 +728,10 @@ int currentTargetIndex = 1;
}
}
foreach (MapEntity mapEntity in MapEntity.mapEntityList)
{
Item item = mapEntity as Item;
if (item == null)
{
//if (!mapEntity.MoveWithLevel) continue;
//mapEntity.Move(velocity);
}
else if (item.body!=null)
{
if (item.CurrentHull != null) continue;
item.body.LinearVelocity += simVelocity;
}
foreach (Item item in Item.itemList)
{
if (item.body==null || item.CurrentHull != null) continue;
item.body.LinearVelocity += simVelocity;
}
AtStartPosition = Vector2.Distance(startPosition, -Position) < ExitDistance;

View File

@@ -110,7 +110,7 @@ namespace Subsurface
{
Character.UpdateAnimAll((float)Physics.step * 1000.0f);
Ragdoll.UpdateAll((float)Physics.step);
Ragdoll.UpdateAll(cam, (float)Physics.step);
GameMain.World.Step((float)Physics.step);

View File

@@ -132,7 +132,7 @@ namespace Subsurface
Debug.WriteLine(" char: " + sw.ElapsedTicks);
sw.Restart();
Ragdoll.UpdateAll((float)Physics.step);
Ragdoll.UpdateAll(cam, (float)Physics.step);
if (GameMain.GameSession != null && GameMain.GameSession.Level != null)
{

Binary file not shown.