Search Unity

Question For a laser bolt for VR - particle collision, collider collision or Raycast, which performs best?

Discussion in 'VR' started by Esfekia, Dec 11, 2023.

  1. Esfekia

    Esfekia

    Joined:
    Mar 28, 2022
    Posts:
    11
    We are currently developing a VR game for oculus devices. We are using XR interaction toolkit and Unity 2023 LTS. The game will utilize 3 way VR which we are building with Netcode for Game Objects.

    We have a drone which will fire laser bolts at the enemy in a "3 bolts in rapid succession, then short break" manner. From my reading online it looks like I can do this in at least 3 different ways.

    a) Create a laser bolt prefab attach the collider/rigidbody, target lock it at the enemy and once it hits, register the hit, play the child impact prefab and return it to object pool,

    b) use physics raycast to check if hit happened, send the laser bolt prefab without any collider rigidbody to the point of contact on raycast and register hit, etc.

    c) Use a particle effect in the form of a laser bolt, set its settings so that it shoots in the manner I explained above, send particle collision data, check for particle collision on target and register the hits, etc.

    Now from my personal tests the most fun and realistic version I could get was c) but I have been told this is not the optimal way especially considering fast moving targets in a multiplayer environment. I have also been told that using b) will net the most accurate "hit registration", but we will need to deal with lag visually with a method similar to how it is handled in Unity's Boss Room showcase project.

    I wanted to ask the community for best practices for handling this type of laser hit in a VR multiplayer environment. Please note that there will be multiple low speed drones (up to 30) in the scene that will fire at each other and faster moving players. We would be grateful for advice in both GPU performance aspect as well as multiplayer/network communication feasibility.

    Best,
     
  2. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,050
    I think most multiplayer games use raycasts. These can also be checked on a server to implement anti cheat.

    If you run into a performance wall you could try to multi thread it (although I don't think this amount will give any issues): https://docs.unity3d.com/ScriptReference/RaycastCommand.html
     
    Esfekia likes this.