fixed: various movement and air control fixes and tweaks, various clean up

This commit is contained in:
Chris
2025-07-29 17:38:52 -04:00
parent 39313c96d0
commit ae1908013d
9 changed files with 52 additions and 37 deletions

View File

@@ -44,6 +44,7 @@ namespace NodeCanvas.Tasks.Actions {
private float currentRotSpeed;
private float lastLookMagnitude;
private Quaternion targetRotation;
private Vector3 currentMoveDir;
// References
private PlayerControls controls;
@@ -56,7 +57,7 @@ namespace NodeCanvas.Tasks.Actions {
// Append the late update method to actually happen on late update
MonoManager.current.onLateUpdate += LateUpdate;
// What
// Set ingitial rotation power
currentRotSpeed = rotationSpeed.value;
// Reference to controls
@@ -68,8 +69,8 @@ namespace NodeCanvas.Tasks.Actions {
//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() {
protected override void OnExecute(){
currentMoveDir = groundMoveDirection.value;
}
//Called once per frame while the action is active.
@@ -92,8 +93,12 @@ namespace NodeCanvas.Tasks.Actions {
if (controls.rawMoveInput.magnitude == 0) { break; }
// Set desired rotation to input direction, with respect to camera rotation
targetRotation = Quaternion.LookRotation(new Vector3(controls.rawMoveInput.x, 0, controls.rawMoveInput.y)) *
Quaternion.Euler(Camera.main.transform.rotation.eulerAngles.Flatten(0f, null, 0f));
if (agent.isGrounded){
targetRotation = Quaternion.LookRotation(currentMoveDir) *
Quaternion.Euler(Camera.main.transform.rotation.eulerAngles.Flatten(0f, null, 0f));
} else {
targetRotation = Quaternion.LookRotation(airMoveDirection.value);
}
break;
case PlayerFacingDirection.MatchCamera:
// Craft a new rotation that flattens the camera's rotation to the ground
@@ -108,10 +113,13 @@ namespace NodeCanvas.Tasks.Actions {
// Construct move direction
Vector3 finalMoveDir = Vector3.zero;
Vector3 gravityMoveDirection;
// Change how input is managed based on facing state
currentMoveDir = Vector3.Slerp(currentMoveDir, groundMoveDirection.value, currentRotSpeed * Time.deltaTime);
// Add input movement
if (agent.isGrounded){
finalMoveDir += groundMoveDirection.value + Vector3.down * .03f;
finalMoveDir += currentMoveDir + Vector3.down * .03f;
gravityMoveDirection = new(0f, jumpPower.value + (Physics.gravity.y *.3f), 0f);
} else {
finalMoveDir += airMoveDirection.value;
@@ -131,7 +139,7 @@ namespace NodeCanvas.Tasks.Actions {
}
// Set final rotation
agent.transform.rotation = Quaternion.Lerp(agent.transform.rotation, targetRotation, 10f * Time.deltaTime);
agent.transform.rotation = Quaternion.Lerp(agent.transform.rotation, targetRotation, 10f * Time.deltaTime).Flatten(0, null, 0);
// ???? Moved this above but don't remember if this needs to be here still
if (agent.isGrounded) {