SFML community forums

Help => General => Topic started by: AvaZip on December 09, 2011, 02:32:14 am

Title: SFML Collision Resolution
Post by: AvaZip 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
Title: SFML Collision Resolution
Post by: AvaZip on December 09, 2011, 04:09:47 am
An example would be nice...
Title: SFML Collision Resolution
Post by: julen26 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
Title: SFML Collision Resolution
Post by: AvaZip on December 09, 2011, 08:43:18 pm
Thanks!