player jump fixes, player eye offset

This commit is contained in:
GoaLitiuM
2021-09-13 18:30:40 +03:00
parent 7ed2f712b2
commit 582b1782e4
3 changed files with 72 additions and 66 deletions

View File

@@ -302,6 +302,7 @@ namespace Game
return traceInfo;
}
#if FLAX_EDITOR
public override void OnDebugDraw()
{
base.OnDebugDraw();
@@ -327,6 +328,7 @@ namespace Game
DebugDraw.DrawWireBox(boxCollider.OrientedBox.GetBoundingBox(), Color.GreenYellow * 0.8f);
}
}
#endif
private SlideMoveHit StepSlideMove(ref Vector3 position, ref Vector3 velocity, bool onGround)
{
@@ -592,9 +594,11 @@ namespace Game
private const float strafeAcceleration = 10f; //QW
private const float airControl = 0f; //CPM
private const float stepSize = 16f;
private const float autoJumpTime = 0.4f;
//private bool physicsInteractions = false;
private bool jumped = false;
private float lastJumped = -1f;
private Vector3 safePosition;
@@ -675,37 +679,39 @@ namespace Game
// TODO: snap to ground here
// jump
if (onGround)
bool jumpAction = InputManager.GetAction("Jump");
if (jumped && !jumpAction)
jumped = false; // jump released
else if (jumped && Time.GameTime - lastJumped >= autoJumpTime)
jumped = false; // jump timeout
if (onGround && jumpAction && !jumped)
{
if (!jumped && InputManager.GetAction("Jump"))
Console.Print("jumping");
// reset velocity from gravity
if (-Vector3.Dot(Physics.Gravity.Normalized, velocity) < 0 &&
Vector3.Dot(velocity, traceGround.hitNormal) < -0.1)
{
// reset velocity from gravity
if (-Vector3.Dot(Physics.Gravity.Normalized, velocity) < 0 &&
Vector3.Dot(velocity, traceGround.hitNormal) < -0.1)
{
velocity = Vector3.ProjectOnPlane(velocity, traceGround.hitNormal);
}
velocity += Vector3.Up * jumpVelocity;
onGround = false;
if (JumpLandSound != null && JumpLandSound.IsLoaded)
{
var audioSource = new AudioSource();
audioSource.Clip = JumpLandSound;
audioSource.Position = rootActor.Position; //new Vector3(-350, 176, 61);//rootActor.Position;
audioSource.Parent = Actor.Parent;
audioSource.Play();
Destroy(audioSource, JumpLandSound.Length);
}
else if (JumpLandSound == null)
Console.Print("jumpAsset not found");
else
Console.Print("jumpAsset not loaded");
velocity = Vector3.ProjectOnPlane(velocity, traceGround.hitNormal);
}
velocity += Vector3.Up * jumpVelocity;
onGround = false;
jumped = true;
lastJumped = Time.GameTime;
if (JumpLandSound != null && JumpLandSound.IsLoaded)
{
var audioSource = new AudioSource();
audioSource.Clip = JumpLandSound;
audioSource.Position = rootActor.Position; //new Vector3(-350, 176, 61);//rootActor.Position;
audioSource.Parent = Actor.Parent;
audioSource.Pitch = 1f;
audioSource.Play();
Destroy(audioSource, JumpLandSound.Length);
}
else if (jumped) // jump released
jumped = false;
}
// ground friction