audio manager, console plugin fixes, demo view angle verifications
This commit is contained in:
@@ -3,8 +3,6 @@ using System.Collections.Generic;
|
||||
using FlaxEngine;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
using FlaxEditor.CustomEditors.Editors;
|
||||
using FlaxEngine.Assertions;
|
||||
using Console = Cabrito.Console;
|
||||
using Debug = FlaxEngine.Debug;
|
||||
using Object = FlaxEngine.Object;
|
||||
@@ -33,12 +31,6 @@ namespace Game
|
||||
[Limit(0, 9000), Tooltip("Base Movement speed")]
|
||||
public float MoveSpeed { get; set; } = 320;
|
||||
|
||||
public AudioClip JumpLandSound;
|
||||
public AudioClip JumpLandSound2;
|
||||
public AudioClip JumpLandSound3;
|
||||
private AudioClip lastJumpLandSound;
|
||||
private Random soundRandom;
|
||||
|
||||
private float viewPitch;
|
||||
private float viewYaw;
|
||||
private float viewRoll;
|
||||
@@ -85,7 +77,6 @@ namespace Game
|
||||
|
||||
rigidBody = Actor.As<RigidBody>();
|
||||
|
||||
soundRandom = new Random();
|
||||
//rigidBody.CollisionEnter += OnCollisionEnter;
|
||||
//rigidBody.TriggerEnter += OnTriggerEnter;
|
||||
//rigidBody.TriggerExit += OnTriggerExit;
|
||||
@@ -185,8 +176,8 @@ namespace Game
|
||||
currentInputFrame2++;
|
||||
}
|
||||
|
||||
private Vector3 fixedPosition = Vector3.Zero;
|
||||
private bool newframe = false;
|
||||
private bool demoDeltasVerify = true;
|
||||
private bool demoDeltasCorrect = true;
|
||||
|
||||
public override void OnFixedUpdate()
|
||||
{
|
||||
@@ -197,25 +188,49 @@ namespace Game
|
||||
PlayerInputState inputState = input.GetCurrentInputState();
|
||||
|
||||
if (input is PlayerInputDemo)
|
||||
{
|
||||
ApplyInputToCamera(inputState);
|
||||
|
||||
// Verify view angles first
|
||||
if (demoDeltasVerify)
|
||||
{
|
||||
Vector3 viewAngles = new Vector3(viewYaw, viewPitch, viewRoll);
|
||||
float viewAnglesDelta = (viewAngles - inputState.verificationViewAngles).Length;
|
||||
if (viewAnglesDelta > 0.00001)
|
||||
{
|
||||
Console.PrintError("Demo verification failed, view angles delta: " + viewAnglesDelta);
|
||||
if (demoDeltasCorrect)
|
||||
{
|
||||
SetCameraEulerAngles(inputState.verificationViewAngles);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
SimulatePlayerMovement(inputState);
|
||||
|
||||
if (input is PlayerInputDemo)
|
||||
if (input is PlayerInputDemo && demoDeltasVerify)
|
||||
{
|
||||
// verify
|
||||
float positionDelta = (Actor.Position - inputState.verificationPosition).Length;
|
||||
if (positionDelta > 0.00001)
|
||||
Console.Print("pos delta: " + positionDelta + " " + (Actor.Position - inputState.verificationPosition));
|
||||
Console.Print("Demo verification failed, position delta: " + positionDelta);
|
||||
|
||||
float velocityDelta = (currentVelocity - inputState.verificationVelocity).Length;
|
||||
if (velocityDelta > 0.00001)
|
||||
Console.Print("pos vel: " + velocityDelta);
|
||||
Console.Print("Demo verification failed, velocity delta: " + velocityDelta);
|
||||
|
||||
float orientationDelta = (rootActor.Orientation - inputState.verificationOrientation).Length;
|
||||
if (orientationDelta > 0.00001)
|
||||
Console.Print("pos orient: " + rootActor.Orientation);
|
||||
{
|
||||
Console.PrintError("Demo verification failed, orientation delta: " + orientationDelta);
|
||||
if (demoDeltasCorrect)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//if (currentInputFrame == 0)
|
||||
/*{
|
||||
@@ -231,24 +246,17 @@ namespace Game
|
||||
position = Actor.Position,
|
||||
velocity = currentVelocity,
|
||||
orientation = rootActor.Orientation,
|
||||
viewYaw = viewYaw,
|
||||
viewPitch = viewPitch,
|
||||
viewRoll = viewRoll
|
||||
viewAngles = new Vector3(viewYaw, viewPitch, viewRoll),
|
||||
});
|
||||
input.OnEndFrame();
|
||||
|
||||
|
||||
|
||||
|
||||
lastInputFrame = currentInputFrame;
|
||||
currentInputFrame++;
|
||||
|
||||
viewPitchLastFrame = viewPitch;
|
||||
viewYawLastFrame = viewYaw;
|
||||
viewRollLastFrame = viewRoll;
|
||||
|
||||
fixedPosition = Actor.Position;
|
||||
newframe = true;
|
||||
}
|
||||
|
||||
private void ApplyInputToCamera(PlayerInputState inputState)
|
||||
@@ -256,17 +264,22 @@ namespace Game
|
||||
// Update camera viewf
|
||||
float xAxis = inputState.viewDeltaX;
|
||||
float yAxis = inputState.viewDeltaY;
|
||||
if (xAxis != 0.0f || yAxis != 0.0f)
|
||||
{
|
||||
var camera = rootActor.GetChild<Camera>();
|
||||
if (xAxis == 0.0f && yAxis == 0.0f)
|
||||
return;
|
||||
|
||||
viewPitch = Mathf.Clamp(viewPitch + yAxis, -90.0f, 90.0f);
|
||||
viewYaw += xAxis;
|
||||
viewPitch = Mathf.Clamp(viewPitch + yAxis, -90.0f, 90.0f);
|
||||
viewYaw += xAxis;
|
||||
|
||||
// root orientation must be set first
|
||||
rootActor.Orientation = Quaternion.Euler(0, viewYaw, 0);
|
||||
camera.Orientation = Quaternion.Euler(viewPitch, viewYaw, viewRoll);
|
||||
}
|
||||
SetCameraEulerAngles(new Vector3(viewYaw, viewPitch, viewRoll));
|
||||
}
|
||||
|
||||
private void SetCameraEulerAngles(Vector3 viewAngles)
|
||||
{
|
||||
Camera camera = rootActor.GetChild<Camera>();
|
||||
|
||||
// Root orientation must be set first
|
||||
rootActor.Orientation = Quaternion.Euler(0, viewAngles.X, 0);
|
||||
camera.Orientation = Quaternion.Euler(viewAngles.Y, viewAngles.X, viewAngles.Z);
|
||||
}
|
||||
|
||||
private static bool SweepPlayerCollider(Actor actor, Vector3 start, Vector3 end, out RayCastHit[] hits)
|
||||
@@ -764,7 +777,7 @@ namespace Game
|
||||
private bool jumped = false;
|
||||
private float lastJumped = -1f;
|
||||
|
||||
private Vector3 safePosition;
|
||||
//private Vector3 safePosition;
|
||||
|
||||
[ReadOnly]
|
||||
public float CurrentVelocity
|
||||
@@ -870,33 +883,7 @@ namespace Game
|
||||
jumped = true;
|
||||
lastJumped = Time.GameTime;
|
||||
|
||||
/*var jumpLandSound = JumpLandSound;
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
var r = soundRandom.Next(3);
|
||||
if (r == 1)
|
||||
jumpLandSound = JumpLandSound2;
|
||||
else if (r == 2)
|
||||
jumpLandSound = JumpLandSound3;
|
||||
|
||||
// avoid repetition
|
||||
if (jumpLandSound != lastJumpLandSound)
|
||||
break;
|
||||
}
|
||||
|
||||
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.Name = jumpLandSound.Path;
|
||||
|
||||
audioSource.Play();
|
||||
Destroy(audioSource, jumpLandSound.Length);
|
||||
lastJumpLandSound = jumpLandSound;
|
||||
}*/
|
||||
AudioManager.PlaySound("jumpland", Actor, rootActor.Position);
|
||||
}
|
||||
|
||||
if (onGround)
|
||||
|
||||
Reference in New Issue
Block a user