SFML community forums

Help => Graphics => Topic started by: CowNation on May 22, 2018, 07:59:55 pm

Title: How to check if a sprite is touching a line
Post by: CowNation on May 22, 2018, 07:59:55 pm
As the title says, I am drawing a line between 2 verticies.. One is located at the local player sprite, the other goes to the mouse. How can I tell if a different sprite is touching the line in between local & my mouse?
Title: Re: How to check if a sprite is touching a line
Post by: Arcade on May 23, 2018, 05:36:46 pm
You are essentially asking how to check for collisions between a line and a rectangle (the sprite's bounding box). This is a common thing in many games, which means you can probably find several good tutorials by just searching the internet for those terms. Here is the first result that came up for me when searching (http://www.jeffreythompson.org/collision-detection/line-rect.php), which may be what you want.