player jump fixes, player eye offset
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user