Search Unity

Get an angle between NavAgent direction and vector to destination

Discussion in 'Scripting' started by astanid, May 7, 2021.

  1. astanid

    astanid

    Joined:
    Apr 5, 2021
    Posts:
    145

    Attached Files:

  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,742
    Pretty sure that's what you want.

    The most obvious thing is this would only be correct if
    transform
    was identical to
    navAgent.transform
    ... is that your problem?
     
  3. astanid

    astanid

    Joined:
    Apr 5, 2021
    Posts:
    145
    nope. I still got an error.
    Vector3.Angle(targetDir, navAgent.transform.forward);
    Angle is not recognized as a method...
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,742
    https://docs.unity3d.com/ScriptReference/Vector3.Angle.html

    Did you make your OWN Vector3? If so, disambiguate by specifying the UnityEngine one explicitly.

    ALSO, please specify that you have compiler error. That changes the problem from "It doesn't work for some strange reason" to "I have an X error in my code.":

    The important parts of an error message are:
    - the description of the error itself (google this; you are NEVER the first one!)
    - the file it occurred in (critical!)
    - the line number and character position (the two numbers in parentheses)

    All of that information is in the actual error message and you must pay attention to it. Learn how to identify it instantly so you don't have to stop your progress and fiddle around with the forum.
     
  5. astanid

    astanid

    Joined:
    Apr 5, 2021
    Posts:
    145
    Assets\Scripts\NavigateMan.cs(92,31): error CS1061: 'object' does not contain a definition for 'Angle' and no accessible extension method 'Angle' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)
    upload_2021-5-7_21-18-14.png
     

    Attached Files:

  6. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,742
    What is the possible meaning of
    private object Vector3;
    on line 13?

    As I suggested, you defined your own Vector3. Don't do that unless you know what you're doing.

    ALSO: don't use
    object
    type variables unless you really know what you're doing. Enjoy the benefits of C# typechecking.
     
    astanid likes this.
  7. astanid

    astanid

    Joined:
    Apr 5, 2021
    Posts:
    145
    yep, my IDE played a trick on me. for some reason at some stage rider add this definition :(
    kinda stupid :(
     
  8. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,742
    Oh Rider... sigh. That Jet-For-Brains piece of program broke our build at least once a week by silently including assemblies that didn't exist on iOS/Android, and then the engineers would commit the changes and they'd blow up the build.

    And it turned out to be SUPER tricky to actually turn that feature off... at the time it required multiple changes to multiple places, and even then sometimes it silently came back on. Maddening...