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

Author Topic: Collision Help  (Read 1978 times)

0 Members and 1 Guest are viewing this topic.

torenf

  • Newbie
  • *
  • Posts: 29
    • View Profile
    • Email
Collision Help
« on: November 17, 2013, 04:09:27 pm »
Hi Guys!
Today i programm a Jump 'n Run but I dont know how to make a Easy Collision like
a Box to Box Collision.If you able to give me some tutorials or if you can give me tips please do it...
Sincerly Toren
« Last Edit: November 17, 2013, 06:15:26 pm by torenf »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Collision Help
« Reply #1 on: November 17, 2013, 05:22:02 pm »
Things might turn out to be a bit more complex than you'd first imagined. Collision detection can be quite tricky and depending on what kind of platformer you want to make, it can also largely vary. This is great article about different approaches.

If you just want to have a intersection detection, then you can do this relatively easy with SFML:
if(rectA.intersects(rectB))

That's essentially just the easy part, the hard part is handling the reaction to it properly, i.e. what should happen once they intersect? Where do I move the boxes?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Collision Help
« Reply #2 on: November 17, 2013, 05:22:20 pm »
1) First learn to use a a little known website generally known as google. Type in "your problem" and then google will use a crystal ball to determine articles/tutorials for your problem.  ;)

2) Read SFML documentation such as this.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

torenf

  • Newbie
  • *
  • Posts: 29
    • View Profile
    • Email
Re: Collision Help
« Reply #3 on: November 17, 2013, 05:38:28 pm »
I know that this is realy tricky ^^ and i looked many tutorials but my english sucks so hard that i cant understand this shit... In my Programm i want that my Player Sprite onto plattforms jump and dont fall through the plattform. This little game should be like mario ^^

PS:Sorry for my english :)

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Collision Help
« Reply #4 on: November 17, 2013, 05:42:45 pm »
This is where logical thinking comes in. We gave you the tools to detect collision, it is now up to you to write logic that handles of the collision. We just can't write everything for you or we might as well write the game ourselves. (collision depends on lots of things, including how you handle your map, entities, code structure, and many of things specific to your code)  ;)

And if it helps, google has a translator that might help you understand those articles.
« Last Edit: November 17, 2013, 05:45:16 pm by zsbzsb »
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

torenf

  • Newbie
  • *
  • Posts: 29
    • View Profile
    • Email
Re: Collision Help
« Reply #5 on: November 17, 2013, 06:11:50 pm »
Thanks Bro,
I going to write the Collision ...
but 1 last question
if i write

Code: [Select]
if(rectA.intersects(rectB))

Can i take Sprites for it?
« Last Edit: November 17, 2013, 06:16:53 pm by torenf »

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Collision Help
« Reply #6 on: November 17, 2013, 06:26:52 pm »
sprite.getGlobalBounds()
// OR
sprite.getLocalBounds()
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

torenf

  • Newbie
  • *
  • Posts: 29
    • View Profile
    • Email
Re: Collision Help
« Reply #7 on: November 17, 2013, 07:49:49 pm »
Thanks for help :)
BB