maint: cleared PlayerMovement

cleared PlayerMovement variables and custom editor
This commit is contained in:
Chris
2025-03-12 17:13:45 -04:00
parent 0ad0c01249
commit 55bbe468df
3 changed files with 7 additions and 366 deletions

6
.idea/.idea.Project Reset/.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@@ -1,168 +1,5 @@
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="True"> <ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="True">
<Style src="project://database/Assets/Core/UI/Editor/Stylesheets/WildsEditors.uss?fileID=7433441132597879392&amp;guid=a6bd99e5b08b3de4190806c83ae5dfff&amp;type=3#WildsEditors" /> <Style src="project://database/Assets/Core/UI/Editor/Stylesheets/WildsEditors.uss?fileID=7433441132597879392&amp;guid=a6bd99e5b08b3de4190806c83ae5dfff&amp;type=3#WildsEditors" />
<Style src="project://database/Assets/Core/UI/Editor/Stylesheets/PlayerMovementStyles.uss?fileID=7433441132597879392&amp;guid=184c6057804f222428c94a16d4412e0c&amp;type=3#PlayerMovementStyles" /> <Style src="project://database/Assets/Core/UI/Editor/Stylesheets/PlayerMovementStyles.uss?fileID=7433441132597879392&amp;guid=184c6057804f222428c94a16d4412e0c&amp;type=3#PlayerMovementStyles" />
<ui:VisualElement style="flex-grow: 1; padding-bottom: 1px;"> <ui:VisualElement style="flex-grow: 1; padding-bottom: 1px;" />
<ui:Foldout text="Sprinting" data-source-type="PlayerMovement, Assembly-CSharp" class="sectionFoldout">
<ui:VisualElement name="VisualElement" class="statusViewer active" style="background-color: rgb(46, 46, 46);">
<ui:Label text="Sprinting" style="padding-right: 10px; padding-bottom: 5px; padding-top: 5px; padding-left: 10px;" />
<Bindings>
<ui:DataBinding property="style.backgroundColor" data-source-path="sprinting" binding-mode="ToTarget" source-to-ui-converters="Bool to Color" />
</Bindings>
</ui:VisualElement>
</ui:Foldout>
<ui:Foldout text="Gravity &amp; Jumping" toggle-on-label-click="true" data-source-type="PlayerMovement, Assembly-CSharp" name="Foldout" class="sectionFoldout" style="width: auto;">
<ui:FloatField label="Gravity Acceleration" value="42.2" class="property-fullwidth">
<Bindings>
<ui:DataBinding property="value" data-source-path="gravityAcceleration" data-source-type="PlayerMovement, Player" binding-mode="TwoWay" />
</Bindings>
</ui:FloatField>
<ui:FloatField label="Jump Height" value="42.2" class="property-fullwidth">
<Bindings>
<ui:DataBinding property="value" data-source-path="jumpHeight" data-source-type="PlayerMovement, Player" binding-mode="TwoWay" />
</Bindings>
</ui:FloatField>
<ui:FloatField label="Jump Deacceleration" value="42.2" class="property-fullwidth">
<Bindings>
<ui:DataBinding property="value" data-source-path="jumpDeacceleration" data-source-type="PlayerMovement, Player" binding-mode="TwoWay" />
</Bindings>
</ui:FloatField>
<ui:VisualElement name="JumpPower" class="group" style="flex-grow: 1;">
<ui:VisualElement name="VisualElement" style="flex-direction: row;">
<ui:Label text="Current Jump Power" enabled="true" enable-rich-text="true" class="title" style="margin-right: 11px;" />
<ui:Label text="0.000" style="width: 60px; color: rgba(210, 210, 210, 0.25);">
<Bindings>
<ui:DataBinding property="text" data-source-path="jumpPower" data-source-type="PlayerMovement, Player" binding-mode="ToTarget" update-trigger="OnSourceChanged" />
</Bindings>
</ui:Label>
</ui:VisualElement>
<ui:Slider high-value="20" fill="true" name="Slider" show-input-field="false" direction="Horizontal" inverted="false" enabled="false" style="flex-grow: 1;">
<Bindings>
<ui:DataBinding property="value" data-source-path="jumpPower" data-source-type="PlayerMovement, Player" binding-mode="ToTarget" />
</Bindings>
</ui:Slider>
</ui:VisualElement>
<ui:VisualElement name="JumpInfo" style="padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px;">
<ui:VisualElement name="VisualElement" enabled="true" style="flex-grow: 1;">
<ui:VisualElement name="GroundJumps" data-source-type="PlayerMovement, Player" data-source-path="groundJumpParams" enabled="true" class="gravityParameters" style="flex-direction: row;">
<ui:VisualElement data-source-path="active" style="flex-grow: 0; width: 20px; margin-right: 8px; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-color: rgb(106, 106, 106);" />
<ui:VisualElement style="flex-grow: 1;">
<ui:Label text="Ground Jump" name="Name" />
<ui:VisualElement name="Properties" style="flex-direction: row;">
<ui:VisualElement name="GravityValue" class="property">
<ui:Label text="Gravity" name="VariableName" />
<ui:FloatField value="0">
<Bindings>
<ui:DataBinding property="value" data-source-path="jumpGravityMultiplier" binding-mode="ToSource" />
</Bindings>
</ui:FloatField>
</ui:VisualElement>
<ui:VisualElement name="HeightValue" class="property">
<ui:Label text="Height&#10;" name="VariableName" />
<ui:FloatField value="0">
<Bindings>
<ui:DataBinding property="value" data-source-path="jumpHeightMultiplier" data-source-type="PlayerMovement+JumpParameters, Player" binding-mode="ToSource" />
</Bindings>
</ui:FloatField>
</ui:VisualElement>
<ui:VisualElement name="DeaccelValue" class="property">
<ui:Label text="Deacceleration" name="VariableName" />
<ui:FloatField value="0">
<Bindings>
<ui:DataBinding property="value" data-source-path="jumpDeaccelMultiplier" binding-mode="ToSource" />
</Bindings>
</ui:FloatField>
</ui:VisualElement>
<ui:VisualElement name="AirJumpCount" class="property">
<ui:Label text="Count" name="VariableName" />
<ui:VisualElement name="VisualElement" style="flex-direction: row; align-items: center;">
<ui:Label text="-" style="font-size: 14px; -unity-font-style: bold; -unity-text-align: middle-left; color: rgba(210, 210, 210, 0.82);" />
</ui:VisualElement>
</ui:VisualElement>
</ui:VisualElement>
</ui:VisualElement>
</ui:VisualElement>
<ui:VisualElement name="GroundJumps" data-source-type="PlayerMovement, Player" data-source-path="initialAirJumpParams" enabled="true" class="gravityParameters" style="flex-direction: row;">
<ui:VisualElement data-source-path="active" style="flex-grow: 0; width: 20px; margin-right: 8px; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-color: rgb(106, 106, 106);" />
<ui:VisualElement style="flex-grow: 1;">
<ui:Label text="Air Jump, Initial" name="Name" />
<ui:VisualElement name="Properties" style="flex-direction: row;">
<ui:VisualElement name="GravityValue" class="property">
<ui:Label text="Gravity" name="VariableName" />
<ui:FloatField value="0">
<Bindings>
<ui:DataBinding property="value" data-source-path="jumpGravityMultiplier" binding-mode="ToSource" />
</Bindings>
</ui:FloatField>
</ui:VisualElement>
<ui:VisualElement name="HeightValue" class="property">
<ui:Label text="Height&#10;" name="VariableName" />
<ui:FloatField value="0">
<Bindings>
<ui:DataBinding property="value" data-source-path="jumpHeightMultiplier" data-source-type="PlayerMovement+JumpParameters, Player" binding-mode="ToSource" />
</Bindings>
</ui:FloatField>
</ui:VisualElement>
<ui:VisualElement name="DeaccelValue" class="property">
<ui:Label text="Deacceleration" name="VariableName" />
<ui:FloatField value="0">
<Bindings>
<ui:DataBinding property="value" data-source-path="jumpDeaccelMultiplier" binding-mode="ToSource" />
</Bindings>
</ui:FloatField>
</ui:VisualElement>
<ui:VisualElement name="AirJumpCount" class="property">
<ui:Label text="Count" name="VariableName" />
<ui:VisualElement name="VisualElement" style="flex-direction: row; align-items: center;">
<ui:Label text="3" data-source-type="PlayerMovement, Player" style="font-size: 14px; -unity-font-style: bold; -unity-text-align: middle-left; color: rgba(210, 210, 210, 0.82);" />
<ui:Label text="/&#10;" enable-rich-text="false" style="color: rgba(210, 210, 210, 0.41);" />
<ui:IntegerField value="3" data-source-type="PlayerMovement, Player" />
</ui:VisualElement>
</ui:VisualElement>
</ui:VisualElement>
</ui:VisualElement>
</ui:VisualElement>
<ui:VisualElement name="GroundJumps" data-source-type="PlayerMovement, Player" data-source-path="followupAirJumpParams" enabled="true" class="gravityParameters" style="flex-direction: row;">
<ui:VisualElement data-source-path="active" style="flex-grow: 0; width: 20px; margin-right: 8px; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-color: rgb(106, 106, 106);" />
<ui:VisualElement style="flex-grow: 1;">
<ui:Label text="Air Jump, Follow-up" name="Name" />
<ui:VisualElement name="Properties" style="flex-direction: row;">
<ui:VisualElement name="GravityValue" class="property">
<ui:Label text="Gravity" name="VariableName" />
<ui:FloatField value="0">
<Bindings>
<ui:DataBinding property="value" data-source-path="jumpGravityMultiplier" binding-mode="ToSource" />
</Bindings>
</ui:FloatField>
</ui:VisualElement>
<ui:VisualElement name="HeightValue" class="property">
<ui:Label text="Height&#10;" name="VariableName" />
<ui:FloatField value="0">
<Bindings>
<ui:DataBinding property="value" data-source-path="jumpHeightMultiplier" data-source-type="PlayerMovement+JumpParameters, Player" binding-mode="ToSource" />
</Bindings>
</ui:FloatField>
</ui:VisualElement>
<ui:VisualElement name="DeaccelValue" class="property">
<ui:Label text="Deacceleration" name="VariableName" />
<ui:FloatField value="0">
<Bindings>
<ui:DataBinding property="value" data-source-path="jumpDeaccelMultiplier" binding-mode="ToSource" />
</Bindings>
</ui:FloatField>
</ui:VisualElement>
<ui:VisualElement name="AirJumpCount" class="property">
<ui:Label text="Count" name="VariableName" />
<ui:VisualElement name="VisualElement" style="flex-direction: row; align-items: center;">
<ui:Label text="3" style="font-size: 14px; -unity-font-style: bold; -unity-text-align: middle-left; color: rgba(210, 210, 210, 0.82);" />
<ui:Label text="/&#10;" enable-rich-text="false" style="color: rgba(210, 210, 210, 0.41);" />
<ui:IntegerField value="3" />
</ui:VisualElement>
</ui:VisualElement>
</ui:VisualElement>
</ui:VisualElement>
</ui:VisualElement>
</ui:VisualElement>
</ui:VisualElement>
</ui:Foldout>
</ui:VisualElement>
</ui:UXML> </ui:UXML>

View File

@@ -8,90 +8,19 @@ using Drawing;
public class PlayerMovement : MonoBehaviour 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 // Raycasts
public RaycastHit forwardRay; public RaycastHit forwardRay;
public RaycastHit leftRay; public RaycastHit leftRay;
public RaycastHit rightRay; 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 // References
private Player thisPlayer; private Player thisPlayer;
private CharacterController controller;
void Awake(){ void Awake(){
thisPlayer = GetComponent<Player>(); thisPlayer = GetComponent<Player>();
controller = GetComponent<CharacterController>();
} }
void OnDrawGizmos(){
}
void Update(){ void Update(){
//CheckContinuedSprinting();
//ProcessFlatSurfaceMovement();
//ProcessRotation();
// // Debug Visualization Tools
// groundJumpParams.UpdateActive(currentJump);
// initialAirJumpParams.UpdateActive(currentJump);
// followupAirJumpParams.UpdateActive(currentJump);
Color forwardRayStatus = Color.red; Color forwardRayStatus = Color.red;
if (forwardRay.collider&& forwardRay.transform.gameObject.layer == LayerMask.NameToLayer("Environment")){ forwardRayStatus = Color.green;} if (forwardRay.collider&& forwardRay.transform.gameObject.layer == LayerMask.NameToLayer("Environment")){ forwardRayStatus = Color.green;}
@@ -99,7 +28,6 @@ public class PlayerMovement : MonoBehaviour
using (Draw.WithColor(forwardRayStatus)) { using (Draw.WithColor(forwardRayStatus)) {
Draw.Line(transform.position + transform.up, transform.position + transform.forward * 2.5f + transform.up); Draw.Line(transform.position + transform.up, transform.position + transform.forward * 2.5f + transform.up);
} }
} }
void FixedUpdate(){ void FixedUpdate(){
@@ -117,134 +45,4 @@ public class PlayerMovement : MonoBehaviour
thisPlayer.controls.graph.SendEvent("RightRay", true, null); 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;
// }
}
} }