Advertisement

Handling collision

Started by April 08, 2018 06:25 PM
1 comment, last by hplus0603 6 years, 7 months ago

Hi ,

I've been working on some on a game server in Unity. And I was wondering how I should handling collision detection.
I'm using TCP at the moment.

 

I thought I'd write a custom tool , that would find all objects in the game scene. And push that to a file. And let the Server read it out. So it know's where are collision objects are.
Not sure if this is the best approach.
 

I also wonderd how to handle character movement correctly. My client sends each 100ms a update of he's position (if they moved).
The server sends each 150ms to all clients all positions.
But I want to check if there are players in he's area. But that would be again a lot of calculations for the server.



https://gyazo.com/d233ca0b4673a00eb62331603281cdf9

 

For a first person shooter, you will typically run the same gameplay/physics code on the server as on the client. This allows the server to make determinations about things like "was the door open" or "could A see B when shooting?" Players will then send their control inputs, rather than their positions/velocities, to the server. This lets the server avoid cheating players that would try to teleport across the level by sending a different position than they were previously in.

If you want a simpler physics model, then yes, you will have to somehow extract collision geometry, and use some collision testing library to check player movement. If you don't care about teleporting (or want to apply a maximum movement speed) then you could check the path from previous player position to current player position every 100 ms. Note that, if the player controls the actor at a higher frame rate, the player may be able to turn a corner that the "straight cut" wouldn't let them turn. Thus, the packets you receive every 100 ms might contain a number of updates -- say, the last 6 simulation steps, if you simulate at 60 fps.

Or you can use a platform that just does all this for you. Unreal Engine or Roblox come to mind as having ready, built-in networked physics, where you don't need to worry so much about it yourself.

enum Bool { True, False, FileNotFound };

This topic is closed to new replies.

Advertisement