This commit is contained in:
GoaLitiuM
2021-03-13 13:43:04 +02:00
parent edb2180c65
commit e2d7fbd40a
49 changed files with 509 additions and 12171 deletions

View File

@@ -238,6 +238,9 @@ namespace Cabrito
Debug.Logger.LogHandler.SendLog += OnSendLog;
Debug.Logger.LogHandler.SendExceptionLog += OnSendExceptionLog;
Console.OnOpen += () => { Screen.CursorVisible = true; Screen.CursorLock = CursorLockMode.None; };
Console.OnClose += () => { Screen.CursorVisible = false; Screen.CursorLock = CursorLockMode.Locked; };
}
private void OnSendLog(LogType level, string msg, FlaxEngine.Object obj, string stackTrace)

View File

@@ -1,5 +1,6 @@
using FlaxEngine;
using Cabrito;
using System.Diagnostics;
namespace Game
{
@@ -17,9 +18,6 @@ namespace Game
private float inputV;
private InputEvent onExit = new InputEvent("Exit");
private InputEvent onDebug1 = new InputEvent("DebugTrigger1");
private InputEvent onDebug2 = new InputEvent("DebugTrigger2");
private InputEvent onDebug3 = new InputEvent("DebugTrigger3");
public override void OnAwake()
{
@@ -30,36 +28,6 @@ namespace Game
if (Console.IsSafeToQuit)
Engine.RequestExit();
};
onDebug1.Triggered += () =>
{
int quality = (int)Graphics.ShadowsQuality;
quality++;
if (quality >= (int)Quality.MAX)
quality = 0;
Graphics.ShadowsQuality = (Quality)quality;
Debug.Log("ShadowsQuality: " + Graphics.ShadowsQuality.ToString());
};
onDebug2.Triggered += () =>
{
int quality = (int)Graphics.ShadowMapsQuality;
quality++;
if (quality >= (int)Quality.MAX)
quality = 0;
Graphics.ShadowMapsQuality = (Quality)quality;
Debug.Log("ShadowMapsQuality: " + Graphics.ShadowMapsQuality.ToString());
};
onDebug3.Triggered += () =>
{
var box = Scene.AddChild<BoxBrush>();
box.Position = Actor.Position;
//Scene.BuildCSG(1000);
var actor = Actor;
Console.Print("howdy");
};
}
public override void OnDestroy()
@@ -67,9 +35,6 @@ namespace Game
base.OnDestroy();
onExit.Dispose();
onDebug1.Dispose();
onDebug2.Dispose();
onDebug3.Dispose();
}
public override void OnStart()
@@ -77,22 +42,14 @@ namespace Game
var initialEulerAngles = Actor.Orientation.EulerAngles;
_pitch = initialEulerAngles.X;
_yaw = initialEulerAngles.Y;
Console.OnOpen += () => { Screen.CursorVisible = true; Screen.CursorLock = CursorLockMode.None; };
Console.OnClose += () => { Screen.CursorVisible = false; Screen.CursorLock = CursorLockMode.Locked; };
}
/// <inheritdoc />
public override void OnUpdate()
{
if (Console.IsOpen)
return;
var camTrans = Actor.Transform;
xAxis = Input.GetAxis("Mouse X");
yAxis = Input.GetAxis("Mouse Y");
xAxis = InputManager.GetAxis("Mouse X");
yAxis = InputManager.GetAxis("Mouse Y");
if (xAxis != 0.0f || yAxis != 0.0f)
{
@@ -102,14 +59,60 @@ namespace Game
camTrans.Orientation = Quaternion.Euler(_pitch, _yaw, 0);
}
inputH = Input.GetAxis("Horizontal");
inputV = Input.GetAxis("Vertical");
inputH = InputManager.GetAxis("Horizontal");
inputV = InputManager.GetAxis("Vertical");
var move = new Vector3(inputH, 0.0f, inputV);
if (!move.IsZero)
{
move.Normalize();
move = camTrans.TransformDirection(move);
camTrans.Translation += move * MoveSpeed * Time.UnscaledDeltaTime;
move = camTrans.TransformDirection(move) * MoveSpeed;
{
Vector3 delta = move * Time.UnscaledDeltaTime;
float movementLeft = delta.Length;
// 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;
Vector3 hitNormal = move.Normalized;
foreach (RayCastHit hitInfo in hitInfos)
{
if (hitInfo.Collider.Parent == Parent)
continue;
if (hitInfo.Distance < hitDistance)
{
hitDistance = hitInfo.Distance;
hitNormal = hitInfo.Normal;
}
//nohit = false;
//break;
}
if (hitDistance != moveDist)
{
//camTrans.Translation = Vector3.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 += -Vector3.Dot(delta, hitNormal) * hitNormal; // correct?
}
camTrans.Translation += delta;
}
}
Actor.Transform = camTrans;

View File

@@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using FlaxEngine;
namespace Game
{
public class CustomCharacterController : CharacterController
{
}
}

View File

@@ -0,0 +1,30 @@
using System.Collections.Generic;
using FlaxEngine;
using Cabrito;
namespace Game
{
public static class InputManager
{
public static bool GetAction(string name)
{
if (Console.IsOpen)
return false;
return Input.GetAction(name);
}
public static float GetAxis(string name)
{
if (Console.IsOpen)
return 0.0f;
return Input.GetAxis(name);
}
public static float GetAxisRaw(string name)
{
if (Console.IsOpen)
return 0.0f;
return Input.GetAxisRaw(name);
}
}
}

View 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;
}*/
}
}
}

29
Source/Game/TestScript.cs Normal file
View File

@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using FlaxEngine;
namespace Game
{
public class TestScript : Script
{
public override void OnStart()
{
// Here you can add code that needs to be called when script is created, just before the first game update
}
public override void OnEnable()
{
// Here you can add code that needs to be called when script is enabled (eg. register for events)
}
public override void OnDisable()
{
// Here you can add code that needs to be called when script is disabled (eg. unregister from events)
}
public override void OnUpdate()
{
// Here you can add code that needs to be called every frame
}
}
}