demo recording stuff
This commit is contained in:
@@ -5,6 +5,7 @@ using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
using FlaxEngine.Assertions;
|
||||
using Console = Cabrito.Console;
|
||||
using Debug = FlaxEngine.Debug;
|
||||
using Object = FlaxEngine.Object;
|
||||
|
||||
namespace Game
|
||||
@@ -45,11 +46,14 @@ namespace Game
|
||||
|
||||
private Actor rootActor;
|
||||
private RigidBody rigidBody;
|
||||
private PlayerInput input;
|
||||
|
||||
public override void OnAwake()
|
||||
{
|
||||
base.OnAwake();
|
||||
|
||||
input = new PlayerInput();
|
||||
|
||||
onExit.Triggered += () =>
|
||||
{
|
||||
if (Console.IsSafeToQuit)
|
||||
@@ -62,6 +66,16 @@ namespace Game
|
||||
//rigidBody.CollisionEnter += OnCollisionEnter;
|
||||
//rigidBody.TriggerEnter += OnTriggerEnter;
|
||||
//rigidBody.TriggerExit += OnTriggerExit;
|
||||
|
||||
input.OpenDemo();
|
||||
}
|
||||
|
||||
public override void OnDisable()
|
||||
{
|
||||
base.OnDisable();
|
||||
|
||||
if (input != null)
|
||||
input.Flush();
|
||||
}
|
||||
|
||||
private List<PhysicsColliderActor> touchingActors = new List<PhysicsColliderActor>();
|
||||
@@ -103,6 +117,68 @@ namespace Game
|
||||
viewRoll = initialEulerAngles.Z;
|
||||
}
|
||||
|
||||
public override void OnUpdate()
|
||||
{
|
||||
input.OnUpdate();
|
||||
|
||||
if (input.frame > 0)
|
||||
{
|
||||
PlayerActorState actorState = input.GetCurrentActorState();
|
||||
Actor.Position = actorState.position;
|
||||
currentVelocity = actorState.velocity;
|
||||
viewYaw = actorState.viewYaw;
|
||||
viewPitch = actorState.viewPitch;
|
||||
viewRoll = actorState.viewRoll;
|
||||
}
|
||||
|
||||
PlayerInputState inputState = input.GetCurrentInputState();
|
||||
|
||||
// Update camera view
|
||||
float xAxis = inputState.viewDeltaX;
|
||||
float yAxis = inputState.viewDeltaY;
|
||||
if (xAxis != 0.0f || yAxis != 0.0f)
|
||||
{
|
||||
var camera = rootActor.GetChild<Camera>();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
input.RecordCurrentActorState(new PlayerActorState()
|
||||
{
|
||||
position = Actor.Position,
|
||||
velocity = currentVelocity,
|
||||
viewYaw = viewYaw,
|
||||
viewPitch = viewPitch,
|
||||
viewRoll = viewRoll
|
||||
});
|
||||
}
|
||||
|
||||
public override void OnFixedUpdate()
|
||||
{
|
||||
input.OnFixedUpdate();
|
||||
PlayerInputState inputState = input.GetCurrentInputState();
|
||||
|
||||
SimulatePlayerMovement(inputState);
|
||||
|
||||
input.RecordCurrentActorState(new PlayerActorState()
|
||||
{
|
||||
position = Actor.Position,
|
||||
velocity = currentVelocity,
|
||||
viewYaw = viewYaw,
|
||||
viewPitch = viewPitch,
|
||||
viewRoll = viewRoll
|
||||
});
|
||||
input.OnEndFrame();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private bool SweepPlayerCollider(Vector3 start, Vector3 end, out RayCastHit[] hits)
|
||||
{
|
||||
Vector3 delta = end - start;
|
||||
@@ -560,25 +636,6 @@ namespace Game
|
||||
return slideMoveHit;
|
||||
}
|
||||
|
||||
public override void OnUpdate()
|
||||
{
|
||||
float xAxis = InputManager.GetAxisRaw("Mouse X");
|
||||
float yAxis = InputManager.GetAxisRaw("Mouse Y");
|
||||
if (xAxis != 0.0f || yAxis != 0.0f)
|
||||
{
|
||||
var camera = rootActor.GetChild<Camera>();
|
||||
|
||||
viewPitch += yAxis;
|
||||
viewYaw += xAxis;
|
||||
|
||||
viewPitch = Mathf.Clamp(viewPitch, -90.0f, 90.0f);
|
||||
|
||||
// root orientation must be set first
|
||||
rootActor.Orientation = Quaternion.Euler(0, viewYaw, 0);
|
||||
camera.Orientation = Quaternion.Euler(viewPitch, viewYaw, viewRoll);
|
||||
}
|
||||
}
|
||||
|
||||
[ReadOnly] public bool onGround = false;
|
||||
|
||||
/*
|
||||
@@ -643,12 +700,12 @@ namespace Game
|
||||
|
||||
private Vector3 currentVelocity;
|
||||
|
||||
public override void OnFixedUpdate()
|
||||
public void SimulatePlayerMovement(PlayerInputState inputState)
|
||||
{
|
||||
Transform rootTrans = rootActor.Transform;
|
||||
|
||||
Vector3 inputDirection =
|
||||
new Vector3(InputManager.GetAxis("Horizontal"), 0.0f, InputManager.GetAxis("Vertical"));
|
||||
new Vector3(inputState.moveRight, 0.0f, inputState.moveForward);
|
||||
Vector3 moveDirection = rootTrans.TransformDirection(inputDirection);
|
||||
|
||||
Vector3 position = rigidBody.Position;
|
||||
@@ -698,7 +755,7 @@ namespace Game
|
||||
|
||||
// TODO: snap to ground here
|
||||
|
||||
bool jumpAction = InputManager.GetAction("Jump");
|
||||
bool jumpAction = inputState.jumping;
|
||||
|
||||
if (jumped && !jumpAction)
|
||||
jumped = false; // jump released
|
||||
|
||||
Reference in New Issue
Block a user