Fall tilting should not be enabled in third person.

This commit is contained in:
UnknownShadow200 2016-06-26 09:21:37 +10:00
parent ec0a9074b9
commit 3a93918a2c
2 changed files with 29 additions and 28 deletions

View File

@ -2,26 +2,26 @@
using System;
using ClassicalSharp.Model;
using OpenTK;
namespace ClassicalSharp.Entities {
/// <summary> Entity component that performs model animation depending on movement speed and time. </summary>
public sealed class AnimatedComponent {
Game game;
Entity entity;
public AnimatedComponent( Game game, Entity entity ) {
this.game = game;
this.entity = entity;
}
public float legXRot, armXRot, armZRot;
public float bobbingHor, bobbingVer, tiltX, tiltY;
public float walkTime, swing, bobStrength = 1, velTiltStrength = 1;
internal float walkTimeO, walkTimeN, swingO, swingN;
internal float leftXRot, leftZRot, rightXRot, rightZRot;
/// <summary> Calculates the next animation state based on old and new position. </summary>
public void UpdateAnimState( Vector3 oldPos, Vector3 newPos, double delta ) {
walkTimeO = walkTimeN;
@ -29,7 +29,7 @@ namespace ClassicalSharp.Entities {
float dx = newPos.X - oldPos.X;
float dz = newPos.Z - oldPos.Z;
double distance = Math.Sqrt( dx * dx + dz * dz );
if( distance > 0.05 ) {
float walkDelta = (float)distance * 2 * (float)(20 * delta);
walkTimeN += walkDelta;
@ -39,14 +39,13 @@ namespace ClassicalSharp.Entities {
}
Utils.Clamp( ref swingN, 0, 1 );
}
const float armMax = 60 * Utils.Deg2Rad;
const float legMax = 80 * Utils.Deg2Rad;
const float idleMax = 3 * Utils.Deg2Rad;
const float idleXPeriod = (float)(2 * Math.PI / 5.0f);
const float idleZPeriod = (float)(2 * Math.PI / 3.5f);
/// <summary> Calculates the interpolated state between the last and next animation state. </summary>
public void GetCurrentAnimState( float t ) {
swing = Utils.Lerp( swingO, swingN, t );
@ -54,32 +53,33 @@ namespace ClassicalSharp.Entities {
float idleTime = (float)game.accumulator;
float idleXRot = (float)(Math.Sin( idleTime * idleXPeriod ) * idleMax);
float idleZRot = (float)(idleMax + Math.Cos(idleTime * idleZPeriod) * idleMax);
armXRot = (float)(Math.Cos( walkTime ) * swing * armMax) - idleXRot;
legXRot = -(float)(Math.Cos( walkTime ) * swing * legMax);
armZRot = -idleZRot;
armZRot = -idleZRot;
bobbingHor = (float)(Math.Cos( walkTime ) * swing * (2.5f/16f));
bobbingVer = (float)(Math.Abs( Math.Sin( walkTime ) ) * swing * (2.5f/16f));
if( !game.ViewBobbing || !entity.onGround )
bobStrength *= 0.9f;
else
bobStrength += 0.1f;
Utils.Clamp( ref bobStrength, 0, 1 );
DoTilt( ref bobStrength, !game.ViewBobbing || !entity.onGround );
if( entity is LocalPlayer ) {
LocalPlayer p = (LocalPlayer)entity;
DoTilt( ref velTiltStrength, p.Hacks.Noclip || p.Hacks.Flying );
tiltX = (float)Math.Cos( walkTime ) * swing * (0.15f * Utils.Deg2Rad);
tiltY = (float)Math.Sin( walkTime ) * swing * (0.15f * Utils.Deg2Rad);
}
if( game.LocalPlayer.Hacks.Noclip || game.LocalPlayer.Hacks.Flying )
velTiltStrength *= 0.9f;
else
velTiltStrength += 0.1f;
Utils.Clamp( ref velTiltStrength, 0, 1 );
tiltX = (float)Math.Cos( walkTime ) * swing * (0.15f * Utils.Deg2Rad);
tiltY = (float)Math.Sin( walkTime ) * swing * (0.15f * Utils.Deg2Rad);
if( entity.Model is HumanoidModel )
CalcHumanAnim( idleXRot, idleZRot );
}
static void DoTilt( ref float tilt, bool reduce ) {
if( reduce ) tilt *= 0.9f;
else tilt += 0.1f;
Utils.Clamp( ref tilt, 0, 1 );
}
void CalcHumanAnim( float idleXRot, float idleZRot ) {
if( game.SimpleArmsAnim ) {
leftXRot = armXRot; leftZRot = armZRot;
@ -90,10 +90,10 @@ namespace ClassicalSharp.Entities {
rightXRot = -rightXRot; rightZRot = -rightZRot;
}
}
const float maxAngle = 110 * Utils.Deg2Rad;
void PerpendicularAnim( float flapSpeed, float idleXRot, float idleZRot,
out float xRot, out float zRot ) {
out float xRot, out float zRot ) {
float verAngle = (float)(0.5 + 0.5 * Math.Sin( walkTime * flapSpeed ) );
zRot = -idleZRot - verAngle * swing * maxAngle;
float horAngle = (float)(Math.Cos( walkTime ) * swing * armMax * 1.5f);

View File

@ -120,6 +120,7 @@ namespace ClassicalSharp {
bobbingHor = (p.anim.bobbingHor * 0.3f) * p.anim.bobStrength;
bobbingVer = (p.anim.bobbingVer * 0.6f) * p.anim.bobStrength;
if( !velTilt ) return;
float vel = Utils.Lerp( p.OldVelocity.Y + 0.08f, p.Velocity.Y + 0.08f, t );
tiltM = tiltM * Matrix4.RotateX( (-vel * 0.05f) * p.anim.velTiltStrength );
}