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

Author Topic: SFML Collision Resolution  (Read 2106 times)

0 Members and 1 Guest are viewing this topic.

AvaZip

  • Newbie
  • *
  • Posts: 3
    • View Profile
SFML Collision Resolution
« on: December 09, 2011, 02:32:14 am »
Hey Guys,

I'm currently developing an 2D SFML Air Hockey Game, and I've got my graphics menu, score,collision detection, and sound effects in my game. The only thing that remains is collision resolution :(. I'm not sure how to start, and I've had no experience with Trigonometry(12 years old :)). Im trying to get the mallet, to hit the puck, so the puck can glide across the board based on how hard the player hits it. Can someone help me?

Thanks for your time!
  :D

AvaZip

  • Newbie
  • *
  • Posts: 3
    • View Profile
SFML Collision Resolution
« Reply #1 on: December 09, 2011, 04:09:47 am »
An example would be nice...

julen26

  • Jr. Member
  • **
  • Posts: 89
    • View Profile
    • http://julen26.blogspot.com
SFML Collision Resolution
« Reply #2 on: December 09, 2011, 11:52:02 am »
If you know the initial velocity and mass of the balls, the conservation of momentun tells us that the momentum of the system before the collision must be the same as the momentum after the collision:
Code: [Select]
momentum: p
mass: m
velocity: v

p = m * v

Conservation of Momentum:
Code: [Select]
m1 * v1 + m2 * u2 = m1 * v1' + m2 * u2'
For calculating velocities after collision, these formulas are used:
Code: [Select]
v1' = (2 * m2 * v2 + v1 * (m1 - m2)) / (m1 + m2)
v2' = (2 * m1 * v1 - v2 * (m1 - m2)) / (m1 + m2)

And you can get the final velocities only knowing the mass of the objects and their initial velocities.

Cheers

AvaZip

  • Newbie
  • *
  • Posts: 3
    • View Profile
SFML Collision Resolution
« Reply #3 on: December 09, 2011, 08:43:18 pm »
Thanks!