The problem is if he walks closer to the starting(original) position the distance decrees.
I need the overall distance
I feel like its simple but i gust cant think anymore T-T
The problem is if he walks closer to the starting(original) position the distance decrees.
I need the overall distance
I feel like its simple but i gust cant think anymore T-T
What are you actually trying to do? Whatâs the actual goal? Do you have code (that doesnât work yet) that we can improve?
i had a code but it was a mass so i deleted it
i have an object and its moving randomly
but if its moving close to the original pos the distance decrees
so im on this forum to understand how to do it right
im new to scripting
If you have two points and need to get the distance between them, you can use Vector3.Distance for that, or simply subtract the Vectors from each other and get the magnitude of the resulting new Vector.
However, if you want to keep track of the total walked distance, then youâd have to remember the last position, calculate the distance between your current and the last position, add that to the total distance walked, and then set your last position to the current position, so you can repeat the above next frame. This should keep track of the total movement you took. Also, since the distance in the above calculation could be negative (moving the other direction), you probably want to get the absolute value instead, using Mathf.Abs().
isnât it âexpensiveâ to calculate 50 enemyâs distance?
if it is: how do i do that in a non costly way?
Make it work first, then profile it, then optimize it. Otherwise youâll never get anything done.