namespacify everything
This commit is contained in:
@@ -1,99 +1,98 @@
|
||||
using FlaxEngine;
|
||||
|
||||
namespace Game
|
||||
namespace Game;
|
||||
|
||||
public class CameraMovement : Script
|
||||
{
|
||||
public class CameraMovement : Script
|
||||
private float viewPitch;
|
||||
private float viewRoll;
|
||||
private float viewYaw;
|
||||
|
||||
[Limit(0, 9000)]
|
||||
[Tooltip("Camera speed")]
|
||||
public float MoveSpeed { get; set; } = 400;
|
||||
|
||||
public override void OnStart()
|
||||
{
|
||||
private float viewPitch;
|
||||
private float viewRoll;
|
||||
private float viewYaw;
|
||||
Float3 initialEulerAngles = Actor.Orientation.EulerAngles;
|
||||
viewPitch = initialEulerAngles.X;
|
||||
viewYaw = initialEulerAngles.Y;
|
||||
viewRoll = initialEulerAngles.Z;
|
||||
}
|
||||
|
||||
[Limit(0, 9000)]
|
||||
[Tooltip("Camera speed")]
|
||||
public float MoveSpeed { get; set; } = 400;
|
||||
public override void OnUpdate()
|
||||
{
|
||||
Transform camTrans = Actor.Transform;
|
||||
Actor rootActor = Actor.GetChild(0);
|
||||
Camera camera = rootActor.GetChild<Camera>();
|
||||
|
||||
public override void OnStart()
|
||||
float xAxis = InputManager.GetAxisRaw("Mouse X");
|
||||
float yAxis = InputManager.GetAxisRaw("Mouse Y");
|
||||
if (xAxis != 0.0f || yAxis != 0.0f)
|
||||
{
|
||||
Float3 initialEulerAngles = Actor.Orientation.EulerAngles;
|
||||
viewPitch = initialEulerAngles.X;
|
||||
viewYaw = initialEulerAngles.Y;
|
||||
viewRoll = initialEulerAngles.Z;
|
||||
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);
|
||||
}
|
||||
|
||||
public override void OnUpdate()
|
||||
float inputH = InputManager.GetAxis("Horizontal");
|
||||
float inputV = InputManager.GetAxis("Vertical");
|
||||
Float3 move = new Float3(inputH, 0.0f, inputV);
|
||||
|
||||
if (!move.IsZero)
|
||||
{
|
||||
Transform camTrans = Actor.Transform;
|
||||
Actor rootActor = Actor.GetChild(0);
|
||||
Camera camera = rootActor.GetChild<Camera>();
|
||||
move.Normalize();
|
||||
move = camera.Transform.TransformDirection(move) * MoveSpeed;
|
||||
|
||||
float xAxis = InputManager.GetAxisRaw("Mouse X");
|
||||
float yAxis = InputManager.GetAxisRaw("Mouse Y");
|
||||
if (xAxis != 0.0f || yAxis != 0.0f)
|
||||
{
|
||||
viewPitch += yAxis;
|
||||
viewYaw += xAxis;
|
||||
Float3 delta = move * Time.UnscaledDeltaTime;
|
||||
float movementLeft = delta.Length;
|
||||
|
||||
viewPitch = Mathf.Clamp(viewPitch, -90.0f, 90.0f);
|
||||
// TODO: check multiple times in case we get stuck in walls
|
||||
|
||||
// root orientation must be set first
|
||||
rootActor.Orientation = Quaternion.Euler(0, viewYaw, 0);
|
||||
camera.Orientation = Quaternion.Euler(viewPitch, viewYaw, viewRoll);
|
||||
}
|
||||
|
||||
float inputH = InputManager.GetAxis("Horizontal");
|
||||
float inputV = InputManager.GetAxis("Vertical");
|
||||
Float3 move = new Float3(inputH, 0.0f, inputV);
|
||||
|
||||
if (!move.IsZero)
|
||||
{
|
||||
move.Normalize();
|
||||
move = camera.Transform.TransformDirection(move) * MoveSpeed;
|
||||
float sphereRadius = 10.0f; // TODO: use collider radius
|
||||
RayCastHit[] hitInfos;
|
||||
float moveDist = delta.Length;
|
||||
Physics.SphereCastAll(Actor.Transform.Translation, sphereRadius, move.Normalized, out hitInfos,
|
||||
moveDist);
|
||||
|
||||
//bool nohit = true;
|
||||
float hitDistance = moveDist;
|
||||
Float3 hitNormal = move.Normalized;
|
||||
foreach (RayCastHit hitInfo in hitInfos)
|
||||
{
|
||||
Float3 delta = move * Time.UnscaledDeltaTime;
|
||||
float movementLeft = delta.Length;
|
||||
if (hitInfo.Collider.Parent == Parent)
|
||||
continue;
|
||||
|
||||
// TODO: check multiple times in case we get stuck in walls
|
||||
|
||||
float sphereRadius = 10.0f; // TODO: use collider radius
|
||||
RayCastHit[] hitInfos;
|
||||
float moveDist = delta.Length;
|
||||
Physics.SphereCastAll(Actor.Transform.Translation, sphereRadius, move.Normalized, out hitInfos,
|
||||
moveDist);
|
||||
|
||||
//bool nohit = true;
|
||||
float hitDistance = moveDist;
|
||||
Float3 hitNormal = move.Normalized;
|
||||
foreach (RayCastHit hitInfo in hitInfos)
|
||||
if (hitInfo.Distance < hitDistance)
|
||||
{
|
||||
if (hitInfo.Collider.Parent == Parent)
|
||||
continue;
|
||||
|
||||
if (hitInfo.Distance < hitDistance)
|
||||
{
|
||||
hitDistance = hitInfo.Distance;
|
||||
hitNormal = hitInfo.Normal;
|
||||
}
|
||||
//nohit = false;
|
||||
//break;
|
||||
hitDistance = hitInfo.Distance;
|
||||
hitNormal = hitInfo.Normal;
|
||||
}
|
||||
|
||||
if (hitDistance != moveDist)
|
||||
//camTrans.Translation = Float3.Lerp(Actor.Transform.Translation, camTrans.Translation, hitDistance);
|
||||
|
||||
//projected = normal * dot(direction, normal);
|
||||
//direction = direction - projected
|
||||
|
||||
//camTrans.Translation += hitNormal * (moveDist - hitDistance); // correct?
|
||||
//camTrans.Translation = hitNormal * (move * hitNormal); // correct?
|
||||
//camTrans.Translation = Actor.Transform.Translation;
|
||||
delta += -Float3.Dot(delta, hitNormal) * hitNormal; // correct?
|
||||
|
||||
camTrans.Translation += delta;
|
||||
//nohit = false;
|
||||
//break;
|
||||
}
|
||||
}
|
||||
|
||||
Actor.Transform = camTrans;
|
||||
if (hitDistance != moveDist)
|
||||
//camTrans.Translation = Float3.Lerp(Actor.Transform.Translation, camTrans.Translation, hitDistance);
|
||||
|
||||
//projected = normal * dot(direction, normal);
|
||||
//direction = direction - projected
|
||||
|
||||
//camTrans.Translation += hitNormal * (moveDist - hitDistance); // correct?
|
||||
//camTrans.Translation = hitNormal * (move * hitNormal); // correct?
|
||||
//camTrans.Translation = Actor.Transform.Translation;
|
||||
delta += -Float3.Dot(delta, hitNormal) * hitNormal; // correct?
|
||||
|
||||
camTrans.Translation += delta;
|
||||
}
|
||||
}
|
||||
|
||||
Actor.Transform = camTrans;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user