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

Author Topic: Collision detection between a vertex and a sprite (or collision box).  (Read 1729 times)

0 Members and 2 Guests are viewing this topic.

The Strangled Bear

  • Newbie
  • *
  • Posts: 8
    • View Profile
    • Email
We are on a game project and we are trying to figure out how to check if a vertex line collides with a sprite.

The vertex is supposed to go from the player position to a position determined by mouse (this part is all done), and then check if certains object collides with the line (this is where we get stuck). We would show some source code, but we basically don't have any code to show, since we don't really know how to approach this.
Any help would be apprechiated!

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Collision detection between a vertex and a sprite (or collision box).
« Reply #1 on: March 15, 2013, 04:50:10 pm »
Collision detection can be quite a complex or at least confusing topic, fortunately you guys are not alone, but there are thousands of other people who had the same problem in the past, that's why you can find a lot with Google. ;)

One result after 1min searching seems promising, although the code is only available if registered, I think, but it's explained quite well.

Some keywords to search for:
  • line rectangle collision detection (if your player is a rectangle)
  • line AABB intersection (if your player is a AABB)
  • line polygon collision detection (if your player is a polygon)

But keep in mind, you'll need some mathematical understanding in most cases. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Nygarda

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: Collision detection between a vertex and a sprite (or collision box).
« Reply #2 on: March 18, 2013, 10:24:01 am »
Thank you for the link eXpl0it3r and the keywords.

I had the same problem, thanks to the post I now understand what I actually want to do and share the knowledge idea. Instead of checking collision on the line you could use a sprite with a specific length and then rotate is relative to the position of the mouse, and use .intersect or .contains when it collides with an object.

Hope this helped.
Best regards Nygarda.