Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Simple Vector Issue?

Discussion in 'Scripting' started by MBS320, Oct 2, 2023.

  1. MBS320

    MBS320

    Joined:
    Mar 13, 2023
    Posts:
    2
    Hey guys, I'm a bit rusty with my vector math and genuinely lost on something I assumed would be very simple. I have a dot A and a dot B. I want A to point to B and so I thought the math for that was position of B - position of A. But I dunno what that's pointing at...

    I also tried to get B to point to A and that points elsewhere.

    I am working on a Unity 2D project, if that makes any difference. Those dots are sprite renderers, but they're working on object positions so that shouldn't matter imo




    What am I doing wrong here? Or am I just remembering everything wrong?
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,468
    Bunny83, MBS320 and CodeSmile like this.
  3. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    3,899
    The math is sound: (B-A) = direction from A to B
    As Melv said, drawing a Ray is what you want here.
     
    Bunny83 and MBS320 like this.
  4. MBS320

    MBS320

    Joined:
    Mar 13, 2023
    Posts:
    2
    Oh my god, I feel like such an idiot now. Thanks guys
     
    MelvMay likes this.
  5. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    3,899
    I know that feeling. On average twice a day. :D
     
    MBS320 and Bunny83 like this.