About Multiplayer FPS Gun game Mechanics

Hi Everyone, I’m still a beginner in using Babylon Js. I’m trying to make a multiplayer gun fps game. For now I have a character and a weapon model that I got from mixamo (https://www.mixamo.com/).I completed the shooting and weapon functions, but I could not add physics and controls to the character. Two of the best examples of the game I’m trying to make;

1.https://shellshock.io/
2.https://zombieswithguns.io/

Do you think physics engine is used? How do you think physics is integrated into the character in the shellshock game? How can the character control mechanism be handled in the best way? What would be the best way to make the character’s hitboxes? The 2 examples I found so far helped me, but I couldn’t understand how to do it in the most correct way. Do you know any examples for this subject?

1.https://playground.babylonjs.com/#LPX1FM#19 (character control)
2.https://www.babylonjs-playground.com/#VADCKV#10 (hitbox)
Many thanks in advance for your answers.

Hi you.
In the case of Shellshock, I speculate that it uses Axis-Aligned-Bounding-Box tests to do the collision handling. ZombiesWithGuns I believe does something similar, but uses a simple voxel representation of the world. In this case a voxel is either occupied or free space.

If we take Shellshock as an example, you really only need a collision engine based on AABB-AABB intersection and resolution. There are numerous sources on the internet, and it is some of the simplest collision checks to implement.
Another reason to avoid a physics engine is the fact that the client and the server will run two different versions of the physics world, and update at different times using different data. When you use a velocity based physics engine, you will Constantly have to correct differences between the client and the server. For this reason most FPS-games use the kinematic approach to entities, as in this case, you can update your entity whenever needed, and one unit on the client, is one unit on the server.

When it comes to hitboxes, I assume Shellshock uses a single box (same as collision) to do any hit testing. ZombiesWithGuns on the other hand, uses all the meshes making up the visual part of the entity. It does not use a skeletal/skinned mesh, but multiple meshes(body, head, leftUpperArm etc)
This is the way I would go, even if I was using a skinned mesh. Just recreate a simplified version of your player using only box primitives in a hierarchy (upper-body is a child of torso, leftUpperArm is a child of upper-body) and give them the exact same animation as your skinned mesh. Now you have a group of boxes to hit test against, and you won’t have to run an animated, skinned mesh on your server. You don’t even have to instantiate these hit boxes for every single entity. In fact, you only need one group. Whenever the server detects a ray hit the bounding box of some entity, you move/rotate the root of the hit boxes according to your entity, set the animation frame of the hit boxes to that of your entity, compute the word matrices, and test against all boxes.

5 Likes

Hi Raggar,
Thanks a lot for your answer. I did research on what you said. I found a few examples. I just don’t fully understand the system. Here is the example I found in the documentation about Axis Aligned Bounding Box: https://www.babylonjs-playground.com/#2DVY2Z#0

Here he was drawing a box for the sphere meshes. Since the character I want to use is from mixmo, I made a capsule collider that can be drawn according to the size of the character. A similar capsule is used in the Unity Character Controller documentation( Unity - Manual: Character Controller). Do you think this will work? Please have a look :https://playground.babylonjs.com/#D6L0HC#2

As you said, the physics engine can be very challenging on the server side, but how can I control the character movements (running, jumping, left and right, etc.) without using the physics engine. I found a few examples here like these?

1)Character Movement Part 1 | Babylon.js Documentation
2) https://playground.babylonjs.com/#9VQJPV#24

Thank you very much for your answer in advance.

1 Like

Using AABBs in the easiest choice, by far. That is what I assume both previously discussed examples use, more or less. Super easy to implement and no need to worry too much about performance as these tests are super fast. This is where I would start if I were you. Look up code on AABB-AABB intersection + resolution. If you absolutely need a capsule shape, you could look up capsule-AABB or capsule-triangle intersections, but these are a bit more advanced and have some edge cases.
I use a capsule shape for my own player entities, but I’m not using a physics engine currently available as a BabylonJS plugin.

If you are still set on using a physics engine(which it seems like you are), just don’t.
Instead isolate the collision part of the physics engine you want to use. This seems like quite a bit of work, but it’s the only way I can think of as of now, other than perhaps using some player controller in AmmoJS.

1 Like

Hey Mehmet, yeah, those examples you linked are great examples of handling player input and moving the character! I would recommend playing around a bit with the code samples and see if you can get your character moving. If you get stuck anywhere, let us know :slight_smile:

2 Likes