Hi,
I’m doing a little shooter and I’m getting a strange behaviours with raycast :
The player’s shoot is a raycast, and it can interact with enemy’s capsule colliders.
It’s a multiplayer game with server validation.
So I have my server :
rewinding the scene exactly how it was at the time of the shot as seen by the shooter,
then processing the shot (Physics.Raycast)
then reverting positions to their actual states.
No problem here, the rewinding is working and I can see on client & server consoles that positions are right.
However, sometimes (often) the raycast miss for the player but hit on the server, or vice versa
The server is moving colliders objects using transform.position = …
“If you move Colliders from scripting or by animation, you need to allow at least one FixedUpdate to be executed so that the physics library can update before a Raycast will hit the Collider at its new position.”
This is most likely due to the changes to the physics system back in 2017.2. There is a setting in the Physics tab that allows you to enable/disable automatically syncing rigidbodies to transforms any time the transform is manually moved. However, it is advised that you leave this setting off for performance reasons (that is, after all, the reason they implemented this aysnc nature in the first place!).
For your case I would suggest manually calling Physics.SyncTransforms after one of these rollbacks so that the rigidbodies are synced with their transforms. It has the same effect as turning on the above-mentioned setting but allows you to manually instigate the effect when you know you need it rather than leaving it on all of the time and incurring the performance cost at all times.
This is useful,Thanks.I changed my Raycast code to FixedUpdate,the Raycast works well. However,in 60 Hz Screen,0.02 FixedTime is enough,in 144Hz Screen,it looks not smooth.So i use this function in Update.