Impact Collision Error Preventing Damage to AI

I have been running into an error that causes an impact sent over the network to fail and not damage the AI if the AI is running.

Steps to recreate in a fresh PUN demo scene:
1. Move AI's Speed Change ability to the bottom of their list of abilities
2. Set Speed Change Start Type to Automatic
3. Join scene with second player and shoot AI with second player

With these steps it is not obvious that anything is wrong but some hits will not register. To clearly see the error add a debug log at line 541 of PunCharacter.cs. (At comment // The object can't be found. Return.)

Based on this section of code it seems like the attempt to recreate the RaycastHit often fails and causes the InitializeImpactCollisionData function to return prematurely which prevents the hit from registering.

It is super important in my PvE game that all players do equal/consistent damage, so any help to figure out this issue would be greatly appreciated thanks!
 
Last edited:
The raycast is needed for surface effects. If you set a breakpoint and draw a debug line how far off is the raycast from hitting the collider? Would doing something like a spherecast with a small radius work?
 
Thank you for the suggestions. The debug line is pretty far off, as you can see in my screenshot. The spherecast seems to improve the issue but I am struggling to achieve 100% success.

My best solution I came up with is to not set the raycast if it can't be successfully created. Here is what my code looks like with that edit.
Code:
// A RaycastHit cannot be sent over the network. Try to recreate it locally based on the position and normal values.
impactDirection.Normalize();
var ray = new Ray(impactPosition - impactDirection, impactDirection);
var raycastSuccessful = true;
if (!collisionData.ImpactCollider.Raycast(ray, out var hit, 3f)) {
    // The object has moved. Do a direct cast to try to find the object.
    ray.origin = collisionData.ImpactCollider.transform.position - impactDirection;
    if (!collisionData.ImpactCollider.Raycast(ray, out hit, 10f)) {
        // The object can't be found.
        raycastSuccessful = false;
    }
}
if (raycastSuccessful) {
    collisionData.SetRaycast(hit);
}

This edit along with a spherecast is the best solution I currently have but it means other players will sometimes not see the surface effect. I think this is good enough for my game but a solution that is 100% successful would be ideal so I am all ears if you have any other suggestions.

I have only done basic testing in the demo scene with up to 3 players using this edit. I am unsure if not setting the raycast will cause other issues down the line. Any insight into if you think this could cause me other issues would also be appreciated (I am still getting familiar with all of your code).
 

Attachments

  • RaycastError.png
    RaycastError.png
    554.8 KB · Views: 2
I think we need to get away from the requirement of using a RaycastHit for the Surface System. This way this cast would be unnecessary since it is more error prone due to lag. This is a more major change that I'm not able to make right now but it is planned.
 
Back
Top