first commit

This commit is contained in:
Chris
2025-03-12 14:22:16 -04:00
commit 0ad0c01249
1999 changed files with 189708 additions and 0 deletions

8
Assets/Scripts/Core.meta Normal file
View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 8e7f861110369ae41824c4e824ee4746
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: f09426c2a21818a429cc18d1d635ff37
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,47 @@
using NodeCanvas.Framework;
using ParadoxNotion.Design;
using UnityEngine;
namespace NodeCanvas.Tasks.Conditions {
[Category("Core/Input")]
[Description("Returns a float from two Vector3s")]
public class GetMovementInputDotProduct : ConditionTask<PlayerControls>{
[SliderField(0f,1f)]
public BBParameter<Vector3> desiredVector3;
public BBParameter<float> tolerance;
public BBParameter<bool> negate;
//Use for initialization. This is called only once in the lifetime of the task.
//Return null if init was successfull. Return an error string otherwise
protected override string OnInit(){
return null;
}
//This is called once each time the task is enabled.
//Call EndAction() to mark the action as finished, either in success or failure.
//EndAction can be called from anywhere.
protected override bool OnCheck(){
Vector3 rawInputVector3 = new(agent.rawMoveInput.x, 0f, agent.rawMoveInput.y);
float dotProduct = Vector3.Dot(desiredVector3.value, rawInputVector3);
//Debug.Log(dotProduct);
if (dotProduct < tolerance.value) {
return true;
}
return false;
}
//Called when the task is disabled.
protected override void OnEnable() {
}
//Called when the task is paused.
protected override void OnDisable() {
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 18fad1a66e9673c4f895560eee9e050d

View File

@@ -0,0 +1,54 @@
using NodeCanvas.Framework;
using ParadoxNotion.Design;
using UnityEngine;
namespace NodeCanvas.Tasks.Actions {
[Category("Core/Movement")]
public class CalculateAirMovement : ActionTask<Transform>{
public BBParameter<Vector3> airMoveDirection;
public BBParameter<Vector3> groundMoveDirection;
private float airControlPower = 1f;
//Use for initialization. This is called only once in the lifetime of the task.
//Return null if init was successfull. Return an error string otherwise
protected override string OnInit() {
return null;
}
//This is called once each time the task is enabled.
//Call EndAction() to mark the action as finished, either in success or failure.
//EndAction can be called from anywhere.
protected override void OnExecute() {
airControlPower = 1f;
}
//Called once per frame while the action is active.
protected override void OnUpdate() {
// Decay Current Air Movement
airMoveDirection.value = Vector3.Lerp(airMoveDirection.value, Vector3.zero, .7f * Time.deltaTime);
// Decay Air Control power
airControlPower = Mathf.Lerp(airControlPower, 0f, 3f * Time.deltaTime);
// Add air control
Vector3 inputVector3 = new(agent.GetComponent<PlayerControls>().rawMoveInput.x, 0f, agent.GetComponent<PlayerControls>().rawMoveInput.y);
float originalMagnitude = airMoveDirection.value.magnitude;
airMoveDirection.value += Camera.main.transform.rotation * inputVector3 * airControlPower;
airMoveDirection.value = Vector3.ClampMagnitude(airMoveDirection.value, originalMagnitude);
}
//Called when the task is disabled.
protected override void OnStop() {
groundMoveDirection.value = agent.GetComponent<CharacterController>().velocity;
EndAction(true);
}
//Called when the task is paused.
protected override void OnPause() {
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 38d61a72cc7757448b3db6c04395cf91

View File

@@ -0,0 +1,49 @@
using NodeCanvas.Framework;
using ParadoxNotion.Design;
using UnityEngine;
using UnityEngine.InputSystem;
namespace NodeCanvas.Tasks.Conditions {
[Category("Core")]
[Description("Check if input condition was matched this frame")]
public class CheckInput : ConditionTask<Transform>{
public BBParameter<string> actionName;
public BBParameter<string> actionValue;
protected override string info {
get { return "Player Input"; }
}
private InputAction action;
//Use for initialization. This is called only once in the lifetime of the task.
//Return null if init was successfull. Return an error string otherwise
protected override string OnInit(){
return null;
}
//Called whenever the condition gets enabled.
protected override void OnEnable(){
action = agent.GetComponent<PlayerInput>().actions.FindAction(actionName.value);
}
//Called whenever the condition gets disabled.
protected override void OnDisable() {
}
//Called once per frame while the condition is active.
//Return whether the condition is success or failure.
protected override bool OnCheck() {
// if (action.type == InputActionType.Button){
if (action.WasPressedThisFrame()) { return true; }
// } else if (action.type == InputActionType.Value) {
//
// }
return false;
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 89d86f6c4779bf2459076f04cdce4c0e

View File

@@ -0,0 +1,154 @@
using System;
using System.Linq;
using NodeCanvas.Framework;
using ParadoxNotion;
using ParadoxNotion.Design;
using UnityEngine;
using UnityEngine.InputSystem;
namespace NodeCanvas.Tasks.Actions {
[Category("Reset/Actions")]
public class Jump : ActionTask<CharacterController> {
public BBParameter<float> jumpStrength;
public BBParameter<Vector3> airMoveDirection;
[Range(0f, 1f)]
public BBParameter<float> standStillJumpStrength;
public BBParameter<float> jumpPower;
[Tooltip("Determines how much current movement vectors into jump direction")]
public BBParameter<float> currentVelocityInheritence;
public BBParameter<Vector3> directionalForce;
public BBParameter<float> directionalForceStrength;
protected override string info {
get { return "Start Jump" ; }
}
//Use for initialization. This is called only once in the lifetime of the task.
//Return null if init was successfull. Return an error string otherwise
protected override string OnInit(){
return null;
}
//This is called once each time the task is enabled.
//Call EndAction() to mark the action as finished, either in success or failure.
//EndAction can be called from anywhere.
protected override void OnExecute(){
// Set jump power
jumpPower.value = jumpStrength.value;
{ /* // The following creates an air movement direction initially constructed from the agent's velocity, but also from subsequent jump inputs
// // Create a vector 3 to hold velocity without jump power or gravity
// Vector3 velocityWithoutY = new(agent.velocity.x, 0f, agent.velocity.z);
// Vector3 jumpLeapVelocity = new (velocityWithoutY.x, velocityWithoutY.y, velocityWithoutY.z);
//
// float inputVelocityMagnitude = velocityWithoutY.magnitude;
// float usableVelocity = 0f;
//
// // Ungrounded players can input a jump command to take their relative velcity as input for the new direction
// if(!agent.isGrounded){
// // Get raw input direction
// Vector3 playerInputVector3 = new(agent.GetComponent<PlayerControls>().rawMoveInput.x, 0f, agent.GetComponent<PlayerControls>().rawMoveInput.y);
//
// // Compare current velocity magnitude against jump strength. This is so air movement with no inherit velocity can be overidden by the new jump.
// usableVelocity = Mathf.Abs(velocityWithoutY.magnitude - jumpStrength.value);
// usableVelocity = Mathf.Max(usableVelocity, 0f);
// usableVelocity /= jumpStrength.value;
// // Debug.Log(usableVelocity);
//
// // Lerp between leaping and adding the full jump strenght, or adding a portion of it
// Vector3 fullNewValueVelocity = agent.transform.rotation * playerInputVector3.normalized * jumpStrength.value;
// Vector3 fullOriginalValueVelocity = velocityWithoutY;
//
// jumpLeapVelocity = Vector3.Lerp(fullNewValueVelocity, fullOriginalValueVelocity, 1f - usableVelocity);
// } else {
//
// }
//
// // Add directional force, for things such as wall bounces
// Vector3 directionalForceDirection = new Vector3(directionalForce.value.x, 0f, directionalForce.value.y);
// jumpLeapVelocity += (agent.transform.rotation * directionalForce.value) * directionalForceStrength.value;
//
//
// jumpLeapVelocity *= currentVelocityInheritence.value;
// if (agent.isGrounded){
// jumpLeapVelocity = Vector3.ClampMagnitude(jumpLeapVelocity, velocityWithoutY.magnitude);
// } else {
// jumpLeapVelocity = Vector3.ClampMagnitude(jumpLeapVelocity, Mathf.Lerp(velocityWithoutY.magnitude, jumpStrength.value, usableVelocity));
// }
//
// // Debug.Log(jumpLeapVelocity);
//
// airMoveDirection.value = jumpLeapVelocity; */ }
// Save current velocity and get current input direction
Vector3 currentVelocityVector3 = new Vector3(agent.velocity.x, 0f, agent.velocity.z);
Vector2 currentInput = agent.GetComponent<PlayerControls>().rawMoveInput;
Vector3 currentInputVector3 = new(currentInput.x, 0f, currentInput.y);
// Ignore rotation for the current velocity
Vector3 currentVelocityWorld = agent.transform.InverseTransformDirection(currentVelocityVector3.normalized);
// Get the dot product between current velocity's direction and current input (UNUSED FOR NOW)
float velocityInputDot = Vector3.Dot(currentVelocityWorld, currentInputVector3);
// Set air move direction
if (agent.isGrounded) {
airMoveDirection.value = currentVelocityVector3;
} else {
// Hold new desired air direction and Dot against the existing air moving directioin
Vector3 desiredAirMoveDirection = currentInputVector3;
float airMoveDirectionDot = Vector3.Dot(desiredAirMoveDirection.normalized, airMoveDirection.value.normalized);
// Check threshold of current XZ velocity- if it's too close to zero, use the jumpStrength for jumping velocity. If it's not, use the current velocity
float velocityThreshold = 4f;
float magnitudeZeroDifference = Mathf.Clamp(currentVelocityVector3.magnitude - velocityThreshold, 0f, Mathf.Infinity) / velocityThreshold; // Divided by maximum to return a 0-1 value. Clamping not required.
float outputVelocity = Mathf.Lerp(jumpStrength.value, currentVelocityVector3.magnitude, Math.Clamp(magnitudeZeroDifference, 0f, 1f));
outputVelocity = Mathf.Min(outputVelocity, Mathf.Lerp(standStillJumpStrength.value * jumpStrength.value, jumpStrength.value * .4f, magnitudeZeroDifference));
// Remap the dot to set -1 (opposing direction) to -.5f, and 1 (same direciton) to 1.2f
// This is done to allow some sideways jumping direction change, but none backwards, and all forwards
float remappedAirDirectionDot = Mathf.Lerp(.3f, 1.2f, airMoveDirectionDot);
remappedAirDirectionDot = Mathf.Clamp(remappedAirDirectionDot, 0f, 1f);
// Lerp between the current direction and the inputted direction based on the previous dot product
Vector3 outputDirection = Vector3.Lerp(currentVelocityVector3.normalized, currentInputVector3.normalized, remappedAirDirectionDot);
// If there is a direction force, lean into that based on it's strength
outputDirection = Vector3.Lerp(outputDirection, directionalForce.value.normalized, directionalForceStrength.value).normalized;
// Extra math to degrade current air move direction by velocity inheritence, before applying new air direction
airMoveDirection.value *= currentVelocityInheritence.value;
// Set air move direciton
airMoveDirection.value += outputDirection * outputVelocity;
}
// Transform and apply rotatio
agent.transform.rotation = Quaternion.LookRotation(airMoveDirection.value);
EndAction(true);
}
//Called once per frame while the action is active.
protected override void OnUpdate(){
}
//Called when the task is disabled.
protected override void OnStop() {
}
//Called when the task is paused.
protected override void OnPause() {
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 86e5b037e41d5bb4b8805890ee72ad29

View File

@@ -0,0 +1,83 @@
using NodeCanvas.Framework;
using ParadoxNotion.Design;
using UnityEngine;
namespace NodeCanvas.Tasks.Actions {
[Category("Core/Movement")]
[Description("Unit flat ground movement")]
public class ProcessFlatLocomotion : ActionTask<CharacterController>{
public BBParameter<float> baseMoveSpeed;
public BBParameter<float> sprintAdditionalSpeed;
public BBParameter<Vector3> moveDirection;
private float sprintPower;
private bool sprinting;
//Use for initialization. This is called only once in the lifetime of the task.
//Return null if init was successfull. Return an error string otherwise
protected override string OnInit() {
return null;
}
//This is called once each time the task is enabled.
//Call EndAction() to mark the action as finished, either in success or failure.
//EndAction can be called from anywhere.
protected override void OnExecute() {
}
//Called once per frame while the action is active.
protected override void OnUpdate() {
// Get current input direction
Vector3 flatSurfaceDirection = Vector3.zero;
if (agent.isGrounded) {
Vector2 rawInput = agent.transform.GetComponent<PlayerControls>().rawMoveInput;
flatSurfaceDirection = new(rawInput.x, 0, rawInput.y);
}
float CalculateSpeed(){
// Calculate sprinting speed
float outputSpeed = 0f;
// Add base speed
outputSpeed += baseMoveSpeed.value;
// Add sprinting speed
// TODO: Take this sprinting section out and move it into it's own task. Sprinting should be a state in the ground locomotion graph.
if (sprinting) {
sprintPower = Mathf.Lerp(sprintPower, 1, sprintAdditionalSpeed.value * Time.deltaTime);
outputSpeed += (sprintAdditionalSpeed.value * sprintPower);
} else {
outputSpeed += (sprintAdditionalSpeed.value * sprintPower);
sprintPower = Mathf.Lerp(sprintPower, 0, sprintAdditionalSpeed.value * Time.deltaTime);
}
return outputSpeed;
}
// Rotate input to forward direction for flat surface
// flatSurfaceDirection = agent.transform.rotation * flatSurfaceDirection;
// Finalize flat surface direction by adding speed
flatSurfaceDirection *= CalculateSpeed();
moveDirection.value = flatSurfaceDirection;
EndAction(true);
}
//Called when the task is disabled.
protected override void OnStop() {
}
//Called when the task is paused.
protected override void OnPause() {
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 808dc54c4ce75e846890125a4f87e516

View File

@@ -0,0 +1,67 @@
using NodeCanvas.Framework;
using ParadoxNotion.Design;
using ParadoxNotion.Services;
using UnityEngine;
namespace NodeCanvas.Tasks.Actions {
[Category("Core/Movement")]
public class ProcessGravity : ActionTask<CharacterController>{
public BBParameter<float> gravityScale = 1f;
public BBParameter<float> gravityAcceleration = 1f;
public BBParameter<float> gravityMax = 8f;
private Vector3 currentVelocity;
private bool freezeVelocity;
private float gravityPower;
//Use for initialization. This is called only once in the lifetime of the task.
//Return null if init was successfull. Return an error string otherwise
protected override string OnInit(){
MonoManager.current.onLateUpdate += LateUpdate;
return null;
}
//This is called once each time the task is enabled.
//Call EndAction() to mark the action as finished, either in success or failure.
//EndAction can be called from anywhere.
protected override void OnExecute() {
}
//Called once per frame while the action is active.
protected override void OnUpdate() {
if (!freezeVelocity && agent.velocity != Vector3.zero){
currentVelocity = new Vector3(agent.velocity.x, 0f, agent.velocity.y);
}
}
void LateUpdate(){
if (agent.isGrounded) {
gravityPower = 0f;
currentVelocity = Vector3.zero;
freezeVelocity = true;
agent.Move(Physics.gravity * .1f * Time.deltaTime);
} else {
if (currentVelocity == Vector3.zero && agent.velocity.y < 0f) {
freezeVelocity = false;
}
Debug.Log(currentVelocity);
agent.Move((Physics.gravity * gravityPower * Time.deltaTime));
}
}
//Called when the task is disabled.
protected override void OnStop() {
EndAction(true);
}
//Called when the task is paused.
protected override void OnPause() {
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 5c6c0f191ca8a3d4cb402d351413dff3

View File

@@ -0,0 +1,129 @@
using NodeCanvas.Framework;
using ParadoxNotion.Design;
using ParadoxNotion.Services;
using Unity.Mathematics;
using UnityEngine;
namespace NodeCanvas.Tasks.Actions {
[Category("Core/Movement")]
[Description("Finalizes movement and sends the final move commands to the controller")]
public class ProcessMovement : ActionTask<CharacterController>{
public BBParameter<Vector3> groundMoveDirection;
public BBParameter<Vector3> airMoveDirection;
[Space(5)]
public BBParameter<float> gravityAcceleration = 1f;
public BBParameter<float> gravityMax = 8f;
public BBParameter<float> jumpPower;
public BBParameter<float> jumpPowerDecay;
public BBParameter<float> rotationSpeed = 5f;
public BBParameter<float> rotationSmoothing;
private float currentRotSpeed;
private Vector3 rotationNoY;
public BBParameter<float> gravityPower;
//Use for initialization. This is called only once in the lifetime of the task.
//Return null if init was successfull. Return an error string otherwise
protected override string OnInit() {
MonoManager.current.onLateUpdate += LateUpdate;
currentRotSpeed = rotationSpeed.value;
return null;
}
//This is called once each time the task is enabled.
//Call EndAction() to mark the action as finished, either in success or failure.
//EndAction can be called from anywhere.
protected override void OnExecute() {
}
//Called once per frame while the action is active.
protected override void OnUpdate(){
// Get input values
Vector2 rawLookInputVector3 = agent.GetComponent<PlayerControls>().rawLookInput;
Vector2 rawMoveInputVector3 = agent.GetComponent<PlayerControls>().rawMoveInput;
gravityPower.value += gravityAcceleration.value * Time.deltaTime;
gravityPower.value = Mathf.Min(gravityPower.value, gravityMax.value);
// Calculate rotation speed
currentRotSpeed = Mathf.Lerp(currentRotSpeed, rotationSpeed.value, rotationSmoothing.value * Time.deltaTime);
// Process input rotation
agent.transform.Rotate(new Vector3(0, agent.GetComponent<PlayerControls>().rawLookInput.x * rotationSpeed.value * 360f * Time.deltaTime)); // *360 to account for a full circle taking a long ass time
// Process movement rotation
if (agent.isGrounded){
// Quaternion cameraRotNoY = Quaternion.Euler(0f, Camera.main.transform.rotation.eulerAngles.y , 0f);
// agent.transform.rotation = Quaternion.Lerp(agent.transform.rotation, Quaternion.LookRotation(agent.transform.position + groundMoveDirection.value), 10f * Time.deltaTime);
} else {
// rotationNoY = airMoveDirection.value;
// rotationNoY.x = 0f;
// rotationNoY.z = 0f;
// agent.transform.rotation = Quaternion.Lerp(agent.transform.rotation, Quaternion.Euler(rotationNoY), 5f * Time.deltaTime);
}
// Construct move direction
Vector3 finalMoveDir = Vector3.zero;
Vector3 gravityMoveDirection;
// Create movement direction for ground movement based on move direction, facing direction, and input
// Start by lerping facing direction towards move direction based on input power
rotationNoY = airMoveDirection.value;
rotationNoY.x = 0f;
rotationNoY.z = 0f;
// agent.transform.rotation = Quaternion.RotateTowards(agent.transform.rotation, Quaternion.Euler(rotationNoY), )
// Vector3 groundMoveDirModified = Vector3.Lerp();
// Add input movement
if (agent.isGrounded){
Quaternion cameraRotNoY = Quaternion.Euler(0f, Camera.main.transform.rotation.eulerAngles.y , 0f);
finalMoveDir += groundMoveDirection.value + Vector3.down * .03f;
gravityMoveDirection = new(0f, jumpPower.value + (Physics.gravity.y *.08f), 0f);
} else {
finalMoveDir += airMoveDirection.value;
gravityMoveDirection = new(0f, jumpPower.value + Physics.gravity.y * gravityPower.value, 0f);
}
// Do final movement
if (agent.isGrounded) {
agent.Move((Camera.main.transform.rotation * finalMoveDir + gravityMoveDirection) * Time.deltaTime);
} else {
agent.Move((finalMoveDir + gravityMoveDirection) * Time.deltaTime);
}
// Reset gravity power when grounded
if (agent.isGrounded) {
gravityPower.value = 0f;
}
if (agent.isGrounded) {
jumpPower.value = 0f;
}
}
// Gravity is processed in LateUpdate (added to MonoManager's onLateUpdate in OnInit())
public void LateUpdate(){
// Decay jump power
jumpPower.value = Mathf.Lerp(jumpPower.value, 0f, jumpPowerDecay.value * Time.deltaTime);
}
//Called when the task is disabled.
protected override void OnStop() {
EndAction(true);
}
//Called when the task is paused.
protected override void OnPause() {
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 69daf571854fd8046a60a7baab64cc18

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 99f42c94513cd47418459d3454124497
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,15 @@
using UnityEngine;
using System;
using Unity.Netcode.Transports.UTP;
public class SessionManager : MonoBehaviour{
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start(){
}
// Update is called once per frame
void Update(){
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 31709e0224b48e24b8e5311541392a97

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 69b7b68bf471ec54bbcd027a9e30d8aa
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,26 @@
using System;
using UnityEngine;
using Sirenix.OdinInspector;
public class Player : MonoBehaviour{
[HideInInspector] public PlayerControls controls;
[HideInInspector] public PlayerMovement movement;
[HideInInspector] public new PlayerCamera camera;
void Awake(){
controls = GetComponent<PlayerControls>();
movement = GetComponent<PlayerMovement>();
}
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 0c0da0317d344ea49b810f0010efefa8

View File

@@ -0,0 +1,12 @@
using UnityEngine;
public class PlayerCamera : MonoBehaviour{
void Start(){
}
// Update is called once per frame
void LateUpdate(){
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: d224dfedffdf96f4896aeee0ce605153

View File

@@ -0,0 +1,52 @@
using System;
using UnityEditor;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.UIElements;
using NodeCanvas;
using NodeCanvas.Framework;
using ParadoxNotion;
public class PlayerControls : MonoBehaviour{
// References
private Player thisPlayer;
// TODO: Turn these into accessors
public Vector2 rawMoveInput;
public Vector2 rawLookInput;
public GraphOwner graph;
void Awake(){
thisPlayer = GetComponent<Player>();
graph = GetComponent<GraphOwner>();
}
void Start(){
}
public void OnMove(InputValue value){
rawMoveInput.x = value.Get<Vector2>().x;
rawMoveInput.y = value.Get<Vector2>().y;
}
public void OnLook(InputValue value){
rawLookInput.x = value.Get<Vector2>().x;
rawLookInput.y = value.Get<Vector2>().y;
}
public void OnSprint(){
SendMessage("StartSprint");
graph.SendEvent<string>("InputEvent", "Sprint", null);
}
public void OnJump(){
SendMessage("StartJump");
graph.SendEvent<string>("InputEvent", "Jump", null);
}
// Update is called once per frame
void Update(){
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 2d0c4f0666ff5f245bf2a135c782127b

View File

@@ -0,0 +1,250 @@
using System;
using Sirenix.OdinInspector;
using UnityEditor;
using UnityEngine;
using Unity.Mathematics;
using NodeCanvas.Framework;
using Drawing;
public class PlayerMovement : MonoBehaviour
{
// Speed
public float baseMoveSpeed = 5f;
public bool sprinting;
public float sprintAddtnlSpeed = 3f;
public float sprintAcceleration = 5f;
private float sprintPower;
// Gravity
private float gravityScale = 0f;
public float gravityAcceleration = 1f;
public float groundJumpGravity; // TODO: If I add more types of jumps, turn this into a class that contains the gravity, strenghth, and deaccel of each jump
public float airJumpGravity;
// Rotation
public float rotationSpeed = 5f;
public bool justATest;
// Jumping
public float jumpHeight;
public float jumpDeacceleration;
public int airJumpsCount;
public float airJumpStrength;
public float airJumpDeacceleration;
public float groundJumpStrength;
public float groundJumpDeacceleration;
[SerializeField] private float jumpPower;
public int airJumpsRemaining;
public JumpProfile groundJumpParams;
public JumpProfile initialAirJumpParams;
public JumpProfile followupAirJumpParams;
public JumpProfile currentJump;
// Raycasts
public RaycastHit forwardRay;
public RaycastHit leftRay;
public RaycastHit rightRay;
[Serializable]
public class JumpProfile{
public float jumpGravityMultiplier;
public float jumpHeightMultiplier;
public float jumpDeaccelMultiplier;
public bool active;
public void UpdateActive(JumpProfile _active){
// if (Mathf.Approximately(_active.jumpHeightMultiplier, jumpHeightMultiplier)) {
// return;
// }
active = true;
}
}
// References
private Player thisPlayer;
private CharacterController controller;
void Awake(){
thisPlayer = GetComponent<Player>();
controller = GetComponent<CharacterController>();
}
void OnDrawGizmos(){
}
void Update(){
//CheckContinuedSprinting();
//ProcessFlatSurfaceMovement();
//ProcessRotation();
// // Debug Visualization Tools
// groundJumpParams.UpdateActive(currentJump);
// initialAirJumpParams.UpdateActive(currentJump);
// followupAirJumpParams.UpdateActive(currentJump);
Color forwardRayStatus = Color.red;
if (forwardRay.collider&& forwardRay.transform.gameObject.layer == LayerMask.NameToLayer("Environment")){ forwardRayStatus = Color.green;}
using (Draw.WithColor(forwardRayStatus)) {
Draw.Line(transform.position + transform.up, transform.position + transform.forward * 2.5f + transform.up);
}
}
void FixedUpdate(){
LayerMask environmentLayer = LayerMask.NameToLayer("Environment");
if (Physics.Raycast(transform.position + Vector3.up, transform.forward, out forwardRay, 2.5f, ~environmentLayer)){
thisPlayer.controls.graph.SendEvent<bool>("ForwardRay", true, null);
}
if (Physics.Raycast(transform.position + Vector3.up, transform.position + Vector3.left, out leftRay, maxDistance: 2f, ~environmentLayer )) {
thisPlayer.controls.graph.SendEvent("LeftRay", true, null);
}
if (Physics.Raycast(transform.position + Vector3.up, transform.position + Vector3.right, out rightRay, maxDistance: 2f, ~environmentLayer )) {
thisPlayer.controls.graph.SendEvent("RightRay", true, null);
}
}
public void ProcessFlatSurfaceMovement(){
// Get current input direction
Vector3 flatSurfaceDirection = Vector3.zero;
if (controller.isGrounded) {
Vector2 rawInput = thisPlayer.controls.rawMoveInput;
flatSurfaceDirection = new(rawInput.x, 0, rawInput.y);
}
// Rotate input to forward direction for flat surface
flatSurfaceDirection = transform.rotation * flatSurfaceDirection;
// Finalize flat surface direction by adding speed
flatSurfaceDirection *= CalculateSpeed();
// Calculate gravity
if (!controller.isGrounded) {
gravityScale = Mathf.Lerp(gravityScale, Physics.gravity.y, gravityAcceleration * Time.deltaTime);
} else {
gravityScale = -.01f;
}
Vector3 gravityDirection = -Physics.gravity * gravityScale;
// Add and deteriorate jump
Vector3 jumpDirection = Vector3.zero;
jumpPower = Mathf.Lerp(jumpPower, 0f, jumpDeacceleration * Time.deltaTime);
jumpDirection = new Vector3(0, jumpPower, 0);
// Move character
// controller.Move((flatSurfaceDirection + gravityDirection) * Time.deltaTime);
// Reset Air Jumps and Jump Power on Grounded
if (controller.isGrounded) {
airJumpsRemaining = airJumpsCount;
jumpPower = 0f;
currentJump = null;
}
// Reset Gravity Scale upon gaining air
if (!controller.isGrounded) {
//gravityScale = 0;
}
}
public void AllocationTest(){
justATest = !justATest;
}
public void ProcessRotation(){
// Get current input direction
Vector2 rawInput = thisPlayer.controls.rawLookInput;
// Rotate character (times 360 to account for a full rotation taking 360 seconds otherwise)
// transform.Rotate(new Vector3(0, rawInput.x * rotationSpeed * 360f * Time.deltaTime));
}
public void StartSprint(){
sprinting = true;
}
public float CalculateSpeed(){
// Calculate sprinting speed
float outputSpeed = 0f;
// Add base speed
outputSpeed += baseMoveSpeed;
// Add sprinting speed
if (sprinting) {
sprintPower = Mathf.Lerp(sprintPower, 1, sprintAcceleration * Time.deltaTime);
outputSpeed += (sprintAddtnlSpeed * sprintPower);
} else {
outputSpeed += (sprintAddtnlSpeed * sprintPower);
sprintPower = Mathf.Lerp(sprintPower, 0, sprintAcceleration * Time.deltaTime);
}
return outputSpeed;
}
void CheckContinuedSprinting(){
if (sprinting) {
// Disable sprinting if analog stick is released too far
if (thisPlayer.controls.rawMoveInput.sqrMagnitude < .5f) {
sprinting = false;
return;
}
// Disable sprinting if analog stick direction is not forward
Vector2 rawInput = thisPlayer.controls.rawMoveInput;
Vector3 rawInputToVector3 = new(rawInput.x, 0, rawInput.y);
float sprintVectorDot = Vector3.Dot(transform.InverseTransformVector(transform.forward), rawInputToVector3);
if (sprintVectorDot < 0.3f) {
sprinting = false;
}
}
}
void StartJump(){
// Replaced with Jump Type System
// if (controller.isGrounded) {
// jumpPower = jumpHeight * groundJumpStrength;
// } else if (!controller.isGrounded && airJumpsRemaining > 0) {
// Debug.Log(controller.isGrounded);
// jumpPower = jumpHeight * airJumpStrength;
// airJumpsRemaining--;
// }
// if (controller.isGrounded) {
// currentJump = groundJumpParams;
// } else if (airJumpsRemaining > 2){
// currentJump = initialAirJumpParams;
// airJumpsRemaining--;
// } else if (airJumpsRemaining > 0) {
// currentJump = followupAirJumpParams;
// }
//
// if (currentJump != null) {
// jumpPower = currentJump.jumpHeightMultiplier;
// }
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: b3b4e13d59527d1429a62dde97c6a001

View File

@@ -0,0 +1,21 @@
{
"name": "Core",
"rootNamespace": "",
"references": [
"GUID:1491147abca9d7d4bb7105af628b223e",
"GUID:2289059ddf1745b4d80a0f184af99d6b",
"GUID:66c2eb417c67ad849907d0769db96dbf",
"GUID:75469ad4d38634e559750d17036d5f7c",
"GUID:de4e6084e6d474788bb8c799d6b461ec",
"GUID:d8b63aba1907145bea998dd612889d6b"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 3c37fe734c185fc48b50bb4fc19e7537
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: