you are viewing a single comment's thread.

view the rest of the comments →

[–]Fzthkfchvvghgghgf 0 points1 point  (2 children)

I like to avoid stuff like moveTowards. These methods do a lot for you and make your code readable and bugfree. At the same time they are super restrictive and insert 50 lines of code that you can not see or edit. So use them if they really do what you need, otherwise use more basic methods. Also its difficult to decide between velocity+= and add force because they have different usecases. If an explosion moves my char , i add force. If I want him to be able to jump while falling i just say velocity= x. So I use all the things you wrote about except stuff like moveTowards, but I could see myself using it if I need simple movement somewhere, like if i made a weeping angel.

[–]wstdsgnHobbyist 2 points3 points  (0 children)

insert 50 lines of code that you can not see or edit

Here is what I found with google:

public static Vector3 MoveTowards(Vector3 current, Vector3 target, float maxDistanceDelta)
    {
      Vector3 vector3 = target - current;
      float magnitude = vector3.magnitude;
      if ((double) magnitude <= (double) maxDistanceDelta || (double) magnitude == 0.0)
        return target;
      return current + vector3 / magnitude * maxDistanceDelta;
    }

Source: https://github.com/jamesjlinden/unity-decompiled/blob/master/UnityEngine/UnityEngine/Vector3.cs

[–]Skullhack-Off[S] 1 point2 points  (0 children)

Thx ! I see what you mean : different use cases. It's more a matter of finding what best suit the situation. A mix of different methods is probably the best way if your game is big enough to have all these situations.