Raycast
Last updated
Last updated
Fish-Networking Pro is required for raycast lag compensation. Over-time projectiles may use another approach and do not require Pro. See Projectiles for more information.
This feature can be setup easily in a few steps.
To begin I am entering the ColliderRollbackDemo scene included with Fish-Networking Pro. You do not need to open the scene, but if you wish to follow along visually you may.
In my scene is an object named EnemySetup. The screen capture below shows two boxes on the 'enemy'. One for the body, and one for the head.
Each hitbox must be on a new object. Generally speaking, the hitbox would be a child of whichever component moves. With an actual humanoid rig, you would probably place the head collider on a child beneath the neck bone.
Notice the 'hitbox' objects are children of the moving component, and only have a collider on them. You may use any collider type.
Next the ColliderRollback script must be added somewhere within your prefab or object. For the sake of simplicity I have mine on the root, with the NetworkObject.
Once added, specify each object you added as a collider within the Collider Parents collection.
To make things easier, place the suffix 'Hitbox' on all your hitbox objects. You can then lock the inspector on your ColliderRollback object, search Hitbox, and quickly drag all entries in at once.
You've completed all the steps required for setting up an object.
To utilize the lag compensation you must also add the RollbackManager script to your Networkmanager object. We have a section on the RollbackManager component to understand what each field does. Once you review the component settings we can move onto the code.
The RollbackManager must know how far back in time to place colliders to obtain accurate hit results. When your client is to fire their weapon you will want to gather the current PreciseTick and include it with your Fire RPC.