D
D
DenisVladimirovich2017-02-09 02:02:11
Java
DenisVladimirovich, 2017-02-09 02:02:11

How to describe the calculation of collisions on the server?

So. People. Hello. I got a question. Here I have a small server in Java. It takes Input from Unity and changes the position that is sent to the client (almost authoritative server). And I faced such a task, namely, how to calculate collisions on the server, or maybe someone knows what a crutch for this case?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
TheTalion, 2017-02-09
@DenisVladimirovich

For simplicity, I will explain on a circle-type collider in 2D space.
A collider with a radius of 3 means that the object can be interacted with at a distance of 3 from the X and Y positions. the object collider is described by such coordinates at the points maximally remote from the center - X+3;Y+3;X-3;Y-3;
Now imagine that the second object is also a circle, but with a radius of 4, so its collider is X+4; Y+4;X-4;Y-4
So, in order to determine the position on the server (in the system of plus coordinates), you need to do something like:
x1 = obj1.position.x+3; y1 = obj1.position.y+3;
x2 = obj2.position.x+4; y2 = obj2.position.y+4;
Based on this, the collision for one side can be found something like this:
If(x1 - x2 < 1 & y1 - y2 < 1){//collision occurred }
Well, here's a crutch. Perhaps more experienced programmers know something better. The description is not quite correct, but in general, the algorithm, I think, is understandable.

A
Alexey Yeletsky, 2017-02-09
@Tiendil

Collisions on the server are considered the same as on the client. Only on the server.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question