I am trying to use the logic for, "is the player moving toward an object". When the player gets close to the object, increment a varaible, else decrement. Seems simple enough.
I've tried using Vector3.Distance with my Players Position and the Object's position, it seems that, when I am outside of the distance, and rotate 180 degrees, than proceed toward the object the varaible decrements when it should increment.
I need to know when the player is moving toward the object or away from the object (facing in any direction). Below is a snippet of code to better illustrate what I am trying to acheive.
Get rid of the distance checks, get rid of the pause variable, and simply debug.log inside the first if statement "moving towards" and in the second one "moving away". Play the game and see if the output is as expected.
If it is, you have some other logic error.
Also, yes, if it's attached to the player you can just use transform.position or transform.forward without having to GameObject.Find itself.
Edit: Also, transform.forward only takes into account the direction the object is facing, not the direction the object is moving. It's more correct to use something like characterController.velocity.normalized or rigidbody.velocity.normalized instead of transform.forward.
You'll have to handle the edge case where velocity.sqrMagnitude ~= 0.
Edit2: Do this, and store off a variable to "Object_1" since Find() is slow to do every frame