how would i make a Boolean turn true if my object moves and back to false if its not moving and display it on a canvas
What’s moving the object?
One way would be to, in Update, compare the object’s position to where it was the last time you checked. If the distance is below Mathf.Epsilon, you’re stopped, otherwise moving.
But depending on how the object is being moved, you may be able to just set a flag when it starts/stops.
The moving object is the player using the w,a,s,d keys to move
But how is it moving? Are you setting transform.position directly or using a Rigidbody with something like AddForce/Velocity etc.
bool isMoving;
float zMovement = Input...//rest of code from script
if(zMovement != 0){isMoving = true;}
else {isMoving = false;}
If you are using navigation agent, then you can also check if velocity magnitude is above a certain threshold.
bool isMoving = GetComponent<NavMeshAgent>().desiredVelocity.magnitude > 0.1f;
–
Game Rules
Unified Visual Scripting Asset with rules engine
https://www.assetstore.unity3d.com/en/#!/content/84383
Sorry but where did you read he was using a NavMeshAgent? Just curious because all I see is Rigidbody.
Anyway:
bool isMoving = characterRigidbody.velocity.magnitude > Mathf.Epsilon;
velocity.magnitude is the speed of the Rigidbody.
Mathf.Epsilon is the smallest floating point number you can have. Just to account for floating point errors or micro jitter.
Adjust the Mathf.Epsilon if needed to something like 0.1f.
You are right, he is not using NavMeshAgent. Apologize. Your approach to check velocity magnitude is correct in his case.
Rigidbodies also sleep when they appear to have come to a halt. So you can check that and avoid fidly float math.