public void Tick(float d) { if (HeadingTowardsTargetNode) { float3 l_initialDirection = math.normalize(CurrentDestination - LocomotionComponent.AssociatedEntity.EntityGameWorld.RootGround.WorldPosition); float3 l_targetPosition = LocomotionComponent.AssociatedEntity.EntityGameWorld.RootGround.WorldPosition + (l_initialDirection * LocomotionComponent.LocomotionData.Speed * d); float3 l_finalDirection = math.normalize(CurrentDestination - l_targetPosition); // If the initial direction is not the same as the final direction, this means that the destination point has been crossed // thus, the destination is reached bool l_isDestinationReached = math.dot(l_initialDirection, l_finalDirection) <= 0.0f; if (l_isDestinationReached) { /* * When the NavigationNode is reached, we set the position to the exact final location. */ l_targetPosition = CurrentDestination; } LocomotionComponent.AssociatedEntity.EntityGameWorld.RootGround.WorldPosition = l_targetPosition; if (l_isDestinationReached) { HeadingTowardsTargetNode = false; NavigationNode l_oldNavigationNode = LocomotionComponent.AssociatedEntity.CurrentNavigationNode; if (OnNavigationNodeReachedEvent != null) { OnNavigationNodeReachedEvent.Invoke(l_oldNavigationNode, CurrentTargetNode); } } else { float3 l_orientationDirection = l_initialDirection.ProjectOnPlane(math.up()); EntityGameWorld.orientTowards(ref LocomotionComponent.AssociatedEntity.EntityGameWorld, ref l_orientationDirection); } } }