fix: walking out of grounded jittering fixed #3
24
Assets/Player/Graphs/GroundedCheckBT.asset
Normal file
24
Assets/Player/Graphs/GroundedCheckBT.asset
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
%YAML 1.1
|
||||||
|
%TAG !u! tag:unity3d.com,2011:
|
||||||
|
--- !u!114 &11400000
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 0}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: 7a686a47eee2fa44cb0a34b5d86e4d5e, type: 3}
|
||||||
|
m_Name: GroundedCheckBT
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
_serializedGraph: '{"type":"NodeCanvas.BehaviourTrees.BehaviourTree","nodes":[{"repeaterMode":2,"repeatTimes":{"_value":1},"_position":{"x":476.0,"y":327.0},"$type":"NodeCanvas.BehaviourTrees.Repeater","$id":"0"},{"_position":{"x":550.0,"y":433.0},"$type":"NodeCanvas.BehaviourTrees.Sequencer","$id":"1"},{"_condition":{"valueA":{"_name":"isGrounded","_targetVariableID":"09b3259f-8b50-439a-ab86-ea3d8a4916f1"},"valueB":{},"$type":"NodeCanvas.Tasks.Conditions.CheckBoolean"},"_position":{"x":458.0,"y":522.0},"$type":"NodeCanvas.BehaviourTrees.WaitUntil","$id":"2"},{"_action":{"airMoveDirection":{"_name":"airMoveDirection","_targetVariableID":"2fc91db6-09dd-4a1f-9195-426a0c44de31"},"inputVector3":{"_name":"groundMoveDirection","_targetVariableID":"a2c4fe25-9549-4bdd-8cec-2dbfc4a8856f"},"$type":"NodeCanvas.Tasks.Actions.SetAirMovement"},"_position":{"x":396.0,"y":655.0},"$type":"NodeCanvas.BehaviourTrees.ActionNode","$id":"3"},{"_condition":{"valueA":{"_name":"isGrounded","_targetVariableID":"09b3259f-8b50-439a-ab86-ea3d8a4916f1"},"valueB":{"_value":true},"$type":"NodeCanvas.Tasks.Conditions.CheckBoolean"},"_position":{"x":715.0,"y":523.0},"$type":"NodeCanvas.BehaviourTrees.WaitUntil","$id":"4"}],"connections":[{"_sourceNode":{"$ref":"0"},"_targetNode":{"$ref":"1"},"$type":"NodeCanvas.BehaviourTrees.BTConnection"},{"_sourceNode":{"$ref":"1"},"_targetNode":{"$ref":"2"},"$type":"NodeCanvas.BehaviourTrees.BTConnection"},{"_sourceNode":{"$ref":"1"},"_targetNode":{"$ref":"4"},"$type":"NodeCanvas.BehaviourTrees.BTConnection"},{"_sourceNode":{"$ref":"2"},"_targetNode":{"$ref":"3"},"$type":"NodeCanvas.BehaviourTrees.BTConnection"}],"canvasGroups":[],"localBlackboard":{"_variables":{}},"derivedData":{"repeat":true,"$type":"NodeCanvas.BehaviourTrees.BehaviourTree+DerivedSerializationData"}}'
|
||||||
|
_objectReferences: []
|
||||||
|
_graphSource:
|
||||||
|
_version: 3.31
|
||||||
|
_category:
|
||||||
|
_comments:
|
||||||
|
_translation: {x: 150, y: -43}
|
||||||
|
_zoomFactor: 1
|
||||||
|
_haltSerialization: 0
|
||||||
|
_externalSerializationFile: {fileID: 0}
|
||||||
8
Assets/Player/Graphs/GroundedCheckBT.asset.meta
Normal file
8
Assets/Player/Graphs/GroundedCheckBT.asset.meta
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: f9aba4b029eacea44966829321f0124a
|
||||||
|
NativeFormatImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
mainObjectFileID: 11400000
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -51,7 +51,7 @@ namespace NodeCanvas.Tasks.Actions {
|
|||||||
// Save current velocity and get current input direction
|
// Save current velocity and get current input direction
|
||||||
Vector3 currentVelocityVector3 = new Vector3(agent.velocity.x, 0f, agent.velocity.z);
|
Vector3 currentVelocityVector3 = new Vector3(agent.velocity.x, 0f, agent.velocity.z);
|
||||||
Vector2 currentInput = agent.GetComponent<PlayerControls>().rawMoveInput;
|
Vector2 currentInput = agent.GetComponent<PlayerControls>().rawMoveInput;
|
||||||
Vector3 currentInputVector3 = new(currentInput.x, 0f, currentInput.y);
|
Vector3 currentInputVector3 = Camera.main.transform.rotation.Flatten(0, null, 0) * new Vector3(currentInput.x, 0f, currentInput.y);
|
||||||
|
|
||||||
// Ignore rotation for the current velocity
|
// Ignore rotation for the current velocity
|
||||||
Vector3 currentVelocityWorld = agent.transform.InverseTransformDirection(currentVelocityVector3.normalized);
|
Vector3 currentVelocityWorld = agent.transform.InverseTransformDirection(currentVelocityVector3.normalized);
|
||||||
@@ -93,10 +93,6 @@ namespace NodeCanvas.Tasks.Actions {
|
|||||||
airMoveDirection.value += outputDirection * outputVelocity;
|
airMoveDirection.value += outputDirection * outputVelocity;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Transform and apply rotatio
|
|
||||||
|
|
||||||
agent.transform.rotation = Quaternion.LookRotation(airMoveDirection.value);
|
|
||||||
|
|
||||||
EndAction(true);
|
EndAction(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ namespace NodeCanvas.Tasks.Actions {
|
|||||||
//EndAction can be called from anywhere.
|
//EndAction can be called from anywhere.
|
||||||
protected override void OnExecute() {
|
protected override void OnExecute() {
|
||||||
airControlPower = 1f;
|
airControlPower = 1f;
|
||||||
|
protected override void OnExecute(){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Called once per frame while the action is active.
|
//Called once per frame while the action is active.
|
||||||
@@ -34,8 +36,9 @@ namespace NodeCanvas.Tasks.Actions {
|
|||||||
|
|
||||||
// Add air control
|
// Add air control
|
||||||
Vector3 inputVector3 = new(agent.GetComponent<PlayerControls>().rawMoveInput.x, 0f, agent.GetComponent<PlayerControls>().rawMoveInput.y);
|
Vector3 inputVector3 = new(agent.GetComponent<PlayerControls>().rawMoveInput.x, 0f, agent.GetComponent<PlayerControls>().rawMoveInput.y);
|
||||||
float originalMagnitude = airMoveDirection.value.magnitude;
|
float originalMagnitude = airMoveDirection.value.magnitude;
|
||||||
airMoveDirection.value += Camera.main.transform.rotation * inputVector3 * airControlPower;
|
airMoveDirection.value += Camera.main.transform.rotation.Flatten(0, null, 0) *
|
||||||
|
inputVector3 * airControlPower;
|
||||||
|
|
||||||
airMoveDirection.value = Vector3.ClampMagnitude(airMoveDirection.value, originalMagnitude);
|
airMoveDirection.value = Vector3.ClampMagnitude(airMoveDirection.value, originalMagnitude);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -96,9 +96,6 @@ namespace NodeCanvas.Tasks.Actions {
|
|||||||
targetRotation = Quaternion.Euler(Camera.main.transform.rotation.eulerAngles.Flatten(0, null, 0));
|
targetRotation = Quaternion.Euler(Camera.main.transform.rotation.eulerAngles.Flatten(0, null, 0));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set final rotation
|
|
||||||
agent.transform.rotation = Quaternion.Lerp(agent.transform.rotation, targetRotation, 10f * Time.deltaTime);
|
|
||||||
|
|
||||||
// Construct move direction
|
// Construct move direction
|
||||||
Vector3 finalMoveDir = Vector3.zero;
|
Vector3 finalMoveDir = Vector3.zero;
|
||||||
@@ -125,6 +122,9 @@ namespace NodeCanvas.Tasks.Actions {
|
|||||||
agent.Move((finalMoveDir + gravityMoveDirection) * Time.deltaTime);
|
agent.Move((finalMoveDir + gravityMoveDirection) * Time.deltaTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set final rotation
|
||||||
|
agent.transform.rotation = Quaternion.Lerp(agent.transform.rotation, targetRotation, 10f * Time.deltaTime);
|
||||||
|
|
||||||
// ???? Moved this above but don't remember if this needs to be here still
|
// ???? Moved this above but don't remember if this needs to be here still
|
||||||
if (agent.isGrounded) {
|
if (agent.isGrounded) {
|
||||||
jumpPower.value = 0f;
|
jumpPower.value = 0f;
|
||||||
|
|||||||
56
Assets/Scripts/Core/Graph Tasks/SetAirMovement.cs
Normal file
56
Assets/Scripts/Core/Graph Tasks/SetAirMovement.cs
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
using NodeCanvas.Framework;
|
||||||
|
using ParadoxNotion.Design;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
|
||||||
|
namespace NodeCanvas.Tasks.Actions {
|
||||||
|
|
||||||
|
[Category("Reset")]
|
||||||
|
[Description("Hard set the air direction to a certain direction")]
|
||||||
|
public class SetAirMovement : ActionTask<Transform>{
|
||||||
|
public BBParameter<Vector3> airMoveDirection;
|
||||||
|
|
||||||
|
public BBParameter<Vector3> inputVector3;
|
||||||
|
public Space fromSpace;
|
||||||
|
public Space toSpace;
|
||||||
|
|
||||||
|
//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() {
|
||||||
|
if (fromSpace == toSpace) {
|
||||||
|
airMoveDirection.value = inputVector3.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// NOTE: I swear to God these absolutely do not work and nobody could convince me otherwise
|
||||||
|
if (fromSpace == Space.World){
|
||||||
|
airMoveDirection.value = Camera.main.transform.rotation.Flatten(0, null, 0) * inputVector3.value;
|
||||||
|
} else {
|
||||||
|
airMoveDirection.value = Camera.main.transform.rotation.Flatten(0, null, 0) * agent.InverseTransformVector(inputVector3.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
EndAction(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Called when the task is disabled.
|
||||||
|
protected override void OnStop() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//Called when the task is paused.
|
||||||
|
protected override void OnPause() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
2
Assets/Scripts/Core/Graph Tasks/SetAirMovement.cs.meta
Normal file
2
Assets/Scripts/Core/Graph Tasks/SetAirMovement.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: f1db555b92ed94543beab7a2106bc2a3
|
||||||
Reference in New Issue
Block a user