Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Drawing a short line between Sprite & Mouse  (Read 1481 times)

0 Members and 1 Guest are viewing this topic.

CowNation

  • Newbie
  • *
  • Posts: 20
    • View Profile
Drawing a short line between Sprite & Mouse
« on: June 09, 2018, 11:31:09 pm »
I have figured out how to draw a line between a sprite and the mouse. I am trying to make the line shorter. I want to draw a bullet pointing towards the cursor. How would I do that?
The game is a top down game. I have tried dividing the mouse cursor's position, also I have tried subtracting it by 5.

Thanks in advance

underdisk

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Re: Drawing a short line between Sprite & Mouse
« Reply #1 on: June 11, 2018, 06:48:29 pm »
You could compute the vector (the actual arrow, direction vector) and then normalize it (meaning chaning it's size to 1, you can easily check how to do that by checking the internet.

Then you can multiply this vector by a constant to get a fixed length (and then return from your vector to your line with math magic)