HeroEngine Forums
Welcome, Guest. Please login or Register for HeroCloud Account.

Author Topic: Create Physics Character on Server  (Read 895 times)


  • Developers
  • *
  • Posts: 15
    • View Profile
Create Physics Character on Server
« on: Jun 24, 14, 08:12:28 AM »

Hello all!

In my game, players have to shoot each other. So to avoid cheating, I want to check on a server, if the bullet hit another player.

I have a bullet on a server, that is moving by some trajectory. For every tick I check with the help of external function RaycastOneHit if the bullet hit some phisic object (wall, building...). But this function doesn't have any reaction for player's!

I create phisics character for each player like that:
Code: [Select]
CreatePhysicsCapsuleCharacter(me, char.physicsNodeID, 0.15, 0.48, 45, 0.15, char.GetPosition(), 9.8).
And update it position like that :
Code: [Select]
TeleportPhysicsCharacter(me, char.physicsNodeID, char.GetPosition())
What have I to do to make character's "visibly" on server for RaycastOneHit or other function's like OverlapSphere, OverlapRay ?


  • General Accounts
  • *
  • Posts: 998
    • View Profile
    • StarKeeper Online
Re: Create Physics Character on Server
« Reply #1 on: Jul 04, 14, 12:48:58 AM »

Physics Character functions

external function CreatePhysicsBoxCharacter(requestingNode as NodeRef, physics_character_id_out references ID, extents as Vector3, slopeLimit as Float, skinWidth as Float, position as Vector3, gravity as Float) as Boolean
external function CreatePhysicsCapsuleCharacter(requestingNode as NodeRef, physics_character_id_out references ID, height as Float, width as Float, slopeLimit as Float, skinWidth as Float, position as Vector3, gravity as Float) as Boolean

The Physics Character functions create a PhysX Character Controller in the physics scene. The character controller is a generic approximation of a character's volume (box or capsule) that can be moved around the scene. The Character Controller, when told to move, will do continuous collision detection and handle wall-sliding, slope limits and steps. This is merely a collision detection system and not intended to mimic the precise movement of animated characters. Nor can it respond in precisely the same way that any arbitrary character controller on the client will. But for some situations, this can be used to detect (with some degree of accuracy) where characters "should" end up. Think of possibilities like knock-back resolution or cheat detection. Moving lots of character controllers is an expensive operation, so this should be done low-frequency and only when necessary. The callback method _PhysicsCharacterCreated(characterID as ID, successful as Boolean) will be called asynchronously with the response of the create request.

external function TeleportPhysicsCharacter(requestingNode as NodeRef, characterID as ID, position as Vector3) as Boolean
external function MovePhysicsCharacter(requestingNode as NodeRef, characterID as ID, positionDelta as Vector3) as Boolean

These functions are used to move the physics character around the scene. Teleportation is movement that ignores collision response. Move requests follow the continuous collision model and may not actually move the character exactly to where the positionDelta describes. Both of these requests receive a callback on method _PhysicsCharacterMoveComplete(characterID as ID, position as Vector3).

Not that teleportation ignores collision response. So if you use teleporting to move the phsyics character it will fail to respond to collision.

Also physicsCharacters are super costly.

For bullets that aren't instant hit operations and need to have slower travel time then instantly. I suggest making them an npc with a bullet AI. It works really nicely, and is much less of a load than trying to manage a ton of physicsCharacters.

I think though if you use move instead of teleport you will be able to get the results but NOTE: that move may not actually move exactly to where positionDelta describes. This is cause it can be different or off based on client inputs and other factors, but would be decently close.

A possible better way is to randomly check players client movement against where the PhysicsCharacter would be and see if they alter a bunch if so you might have a cheater, flag them, and have them checked out. In more details. Trying to check bullet versus client every time can get costly load wise.


  • World Owners
  • ****
  • Posts: 524
    • View Profile
    • World Wide Zed
Re: Create Physics Character on Server
« Reply #2 on: Jul 04, 14, 11:47:48 AM »

to tell if the bullet hit i would make the assumption that the bullet travels instantly. Use the players heading to work out if they are facing a player with some vector maths. If they are facing exactly , then perform the raycast at the height of the gun to the target , if it comes back empty the bullet hits.

thats the basic idea , there is probably a few extra maths bits you want to account for that i am forgetting like the rotation of the gun , but the main point is the raycast is checking the route is clear , the server already knows the positions and rotations of the players.

as keeper says its more difficult if you want non instant bullet travel.