SFML community forums

Help => Graphics => Topic started by: CowNation on June 09, 2018, 11:31:09 pm

Title: Drawing a short line between Sprite & Mouse
Post by: CowNation 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
Title: Re: Drawing a short line between Sprite & Mouse
Post by: underdisk 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)