Author Topic: Faking Unity Physics, Manually calculating Sphere Collisions[SOLVED]  (Read 1273 times)


  • Playmaker Newbie
  • *
  • Posts: 48
    • View Profile
Hi, wasn't sure the best place to post this, as I guess this isn't a Playmaker-specific issue, but you guys have been really helpful in the past, so thought I'd get your thoughts/suggestions!

Basically, I'm creating an online multiplayer golf game, and inter-player collisions are a huge part of it. Being heavily physics-based, it's a bit of an issue due to it being online multiplayer, sometimes the local player will hit another ball, but due to a slight delay this doesn't always appear to hit the other networked player on their end, so their player doesn't react as it should. I've tried some solutions, like a server-authoratitive setup, and TrueSync, but both haven't really worked out - bit too slow or buggy.

So I've decided best course of action might be to basically turn off the colliders between the two players, and instead make them a trigger, so I can then manually work out the forces that should be applied to them both and trigger this on both players with an RPC. This in theory should guarantee both players are affected by a collision, even if there is a slight delay that is applied to the other networked player. So in essence, player1 hits player2, which triggers an event, which then forces them to react.

The triggering is all working fine, and only happens once per event, so all good. It's literally just the actual calculating of the exit velocities of the two players that I'm a bit stumped on! I'm not worried about spin, or different sized balls, or anything like that. Just a basic, elastic/billiards-like collision. Both players have a rigidbody on them also, so I assumed this should be quite simple, but just can't quite figure it out.

This post seems to explain exactly what I'm after:

But it's the 3rd stage, when it comes to calculating the exit velocities (requiring conservation of linear momentum? that I get completely stumped. I can't quite get my head around the rough concept/pseudo-code I'd need to implement that stage.

This is literally the last piece of the puzzle before the game's fully functional, so would love to get this sorted if I can - does anyone have any ideas/suggestions? Thanks so much!

Edit: Just in case anybody finds this looking for an answer, I did manage to get this working in the end- the maths was a bit above my head, but I got a formula that seems to working pretty accurately. Don't have the logic/code to hand, but if anyone needs it just holla and I can dig it up for you
« Last Edit: July 16, 2018, 05:32:05 AM by jeanfabre »