hmm
This commit is contained in:
116
Source/Game/PlayerMovement.cs
Normal file
116
Source/Game/PlayerMovement.cs
Normal file
@@ -0,0 +1,116 @@
|
||||
using FlaxEngine;
|
||||
using Cabrito;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Game
|
||||
{
|
||||
public class PlayerMovement : Script
|
||||
{
|
||||
[Limit(0, 9000), Tooltip("Base Movement speed")]
|
||||
public float MoveSpeed { get; set; } = 320;
|
||||
|
||||
private float viewPitch;
|
||||
private float viewYaw;
|
||||
private float viewRoll;
|
||||
|
||||
private InputEvent onExit = new InputEvent("Exit");
|
||||
|
||||
Actor rootActor;
|
||||
public override void OnAwake()
|
||||
{
|
||||
base.OnAwake();
|
||||
/*
|
||||
onExit.Triggered += () =>
|
||||
{
|
||||
if (Console.IsSafeToQuit)
|
||||
Engine.RequestExit();
|
||||
};
|
||||
|
||||
rootActor = Actor.GetChild(0);*/
|
||||
}
|
||||
|
||||
public override void OnDestroy()
|
||||
{
|
||||
/*base.OnDestroy();
|
||||
|
||||
onExit.Dispose();*/
|
||||
}
|
||||
|
||||
public override void OnStart()
|
||||
{
|
||||
/*var initialEulerAngles = Actor.Orientation.EulerAngles;
|
||||
viewPitch = initialEulerAngles.X;
|
||||
viewYaw = initialEulerAngles.Y;
|
||||
viewRoll = initialEulerAngles.Z;*/
|
||||
}
|
||||
|
||||
Vector3 wishVelocity = new Vector3(0);
|
||||
public override void OnFixedUpdate()
|
||||
{
|
||||
/*if (Console.IsOpen)
|
||||
return;
|
||||
|
||||
var camera = rootActor.GetChild<Camera>();
|
||||
var camTrans = camera.Transform;
|
||||
var rootTrans = rootActor.Transform;
|
||||
|
||||
float inputH = InputManager.GetAxis("Horizontal");
|
||||
float inputV = InputManager.GetAxis("Vertical");
|
||||
var move = new Vector3(inputH, 0.0f, inputV);
|
||||
|
||||
var rigidBody = Actor.As<RigidBody>();
|
||||
|
||||
|
||||
Vector3 accel = new Vector3(0);
|
||||
|
||||
if (!move.IsZero)
|
||||
{
|
||||
move.Normalize();
|
||||
|
||||
move = rootTrans.TransformDirection(move) * 10;
|
||||
|
||||
accel = move;
|
||||
|
||||
var groundVelocity = rigidBody.LinearVelocity;
|
||||
groundVelocity.Y = 0;
|
||||
|
||||
if (groundVelocity.Length > MoveSpeed)
|
||||
accel = new Vector3(0);
|
||||
//wishVelocity = move;
|
||||
}
|
||||
//else if (!wishVelocity.IsZero)
|
||||
// wishVelocity = new Vector3(0);
|
||||
|
||||
//rigidBody.Position += wishVelocity * Time.DeltaTime;
|
||||
//rigidBody.AddForce(accel, ForceMode.Acceleration);
|
||||
rigidBody.LinearVelocity += accel;
|
||||
//rigidBody.LinearVelocity = wishVelocity;
|
||||
//rigidBody.LinearVelocity /= Time.DeltaTime;
|
||||
*/
|
||||
}
|
||||
|
||||
public override void OnUpdate()
|
||||
{
|
||||
/*float xAxis = InputManager.GetAxis("Mouse X");
|
||||
float yAxis = InputManager.GetAxis("Mouse Y");
|
||||
if (xAxis != 0.0f || yAxis != 0.0f)
|
||||
{
|
||||
var camera = rootActor.GetChild<Camera>();
|
||||
var camTrans = camera.Transform;
|
||||
var rootTrans = rootActor.Transform;
|
||||
|
||||
viewPitch += yAxis;
|
||||
viewYaw += xAxis;
|
||||
|
||||
viewPitch = Mathf.Clamp(viewPitch, -90.0f, 90.0f);
|
||||
|
||||
camTrans.Orientation = Quaternion.Euler(viewPitch, viewYaw, viewRoll);
|
||||
rootTrans.Orientation = Quaternion.Euler(0, viewYaw, 0);
|
||||
|
||||
camera.Transform = camTrans;
|
||||
rootActor.Transform = rootTrans;
|
||||
}*/
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user