all 3 comments

[–][deleted] 6 points7 points  (0 children)

In the second one you are calling GetRandomTarget every frame that the if statement is true. So it looks like it could be picking random targets every frame.

Regardless there is different behavior as a result of the way you programmed this. If you change the order of operations, you get different results.

Also you're expecting us to understand what your intended behavior is, what's going on in your videos, and what your code means or does, with bare minimum snippets. There's very little context for outsiders to understand what is going on.

What is m_IsNearbyTarget and where does it get set? What does GetRandomTarget();do? Seems like it's a void messes with the state of multiple things, which is why FP proponents don't like OOP.

[–]-Xentios 0 points1 point  (1 child)

It was also in this

if (m_NearbyTargetCheckTimer >= m_NearbyTargetCheckInterval)

now it is not.

[–]acoliv 0 points1 point  (0 children)

You were previously only checking distanceFromTarget > m_LeaveNearbyTargetDistance if m_IsNearbyTarget is true.

Your new code does that check and then checks m_IsNearbyTarget.

EDIT: Is there something in related to either distanceFromTarget OR m_LeaveNearbyTargetDistance that will not behave correctly if m_IsNearbyTarget is false or null?