118 lines
3.1 KiB
C#
118 lines
3.1 KiB
C#
using System;
|
|
using System.Collections;
|
|
using NodeCanvas.Framework;
|
|
using ParadoxNotion.Design;
|
|
using ParadoxNotion.Services;
|
|
using Unity.Cinemachine;
|
|
using Unity.Mathematics;
|
|
using UnityEngine;
|
|
using Reset.Movement;
|
|
|
|
namespace Reset.Movement{
|
|
public enum PlayerFacingDirection{
|
|
Target = 0,
|
|
Movement,
|
|
MatchCamera,
|
|
Static
|
|
}
|
|
}
|
|
|
|
|
|
namespace NodeCanvas.Tasks.Actions {
|
|
|
|
[Category("Reset/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;
|
|
|
|
|
|
|
|
// Rotation
|
|
public BBParameter<PlayerFacingDirection> playerFacingDirection;
|
|
|
|
|
|
|
|
|
|
private float lastLookMagnitude;
|
|
|
|
private Vector3 currentMoveDir;
|
|
|
|
// References
|
|
private PlayerControls controls;
|
|
|
|
|
|
|
|
//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() {
|
|
// Append the late update method to actually happen on late update
|
|
|
|
|
|
|
|
// Reference to controls
|
|
controls = agent.GetComponent<PlayerControls>();
|
|
|
|
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(){
|
|
currentMoveDir = groundMoveDirection.value;
|
|
}
|
|
|
|
//Called once per frame while the action is active.
|
|
protected override void OnUpdate(){
|
|
|
|
// Construct move direction
|
|
Vector3 finalMoveDir = Vector3.zero;
|
|
|
|
// Change how input is managed based on facing state
|
|
currentMoveDir = Vector3.Slerp(currentMoveDir, groundMoveDirection.value, 1f * Time.deltaTime); // NOTE: This used to be t: currentRotSpeed * Time.deltaTime.
|
|
// See how it feels with a hard set value and go fro there.
|
|
|
|
// Add input movement
|
|
if (agent.isGrounded){
|
|
finalMoveDir += currentMoveDir; // + Vector3.down * .03f;
|
|
} else {
|
|
finalMoveDir += currentMoveDir;
|
|
}
|
|
|
|
switch (playerFacingDirection.value) {
|
|
|
|
}
|
|
|
|
finalMoveDir += new Vector3(controls.rawMoveInput.x, 0f, controls.rawMoveInput.y);
|
|
|
|
// Do final movement
|
|
if (agent.isGrounded) {
|
|
agent.Move((Quaternion.Euler(Camera.main.transform.rotation.eulerAngles.Flatten(0f, null, 0f)) * finalMoveDir) * Time.deltaTime);
|
|
} else {
|
|
agent.Move((Quaternion.Euler(Camera.main.transform.rotation.eulerAngles.Flatten(0f, null, 0f)) * finalMoveDir) * Time.deltaTime);
|
|
// agent.Move((finalMoveDir) * Time.deltaTime);
|
|
}
|
|
|
|
// ???? Moved this above but don't remember if this needs to be here still
|
|
// if (agent.isGrounded) {
|
|
// jumpPower.value = 0f;
|
|
// }
|
|
EndAction(true);
|
|
|
|
}
|
|
|
|
// Gravity is processed in LateUpdate (added to MonoManager's onLateUpdate in OnInit())
|
|
|
|
|
|
//Called when the task is disabled.
|
|
protected override void OnStop() {
|
|
EndAction(true);
|
|
}
|
|
|
|
//Called when the task is paused.
|
|
protected override void OnPause() {
|
|
|
|
}
|
|
}
|
|
} |