Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Resolved 1.0.0-exp.8 raycasting in netcode

Discussion in 'NetCode for ECS' started by wrp8314, Oct 13, 2022.

  1. wrp8314

    wrp8314

    Joined:
    May 13, 2020
    Posts:
    6
    Hi all. Please tell me why this code does not work if I add the netcode package, but works fine if netcode package is not installed

    entities version 1.0.0-exp.8

    Code (CSharp):
    1. using UnityEngine;
    2. using Unity.Entities;
    3. using Unity.Mathematics;
    4. using Unity.Physics;
    5.  
    6. public unsafe partial class RaycastDebugSystem : SystemBase
    7. {
    8.     public Entity Raycast(CollisionWorld collisionWorld, float3 RayFrom, float3 RayTo)
    9.     {
    10.         RaycastInput input = new()
    11.         {
    12.             Start = RayFrom,
    13.             End = RayTo,
    14.             Filter = new CollisionFilter()
    15.             {
    16.                 BelongsTo = ~0u,
    17.                 CollidesWith = ~0u,
    18.                 GroupIndex = 0
    19.             }
    20.         };
    21.  
    22.         Unity.Physics.RaycastHit hit = new();
    23.         bool haveHit = collisionWorld.CastRay(input, out hit);
    24.         if (haveHit)
    25.         {
    26.             return hit.Entity;
    27.         }
    28.         return Entity.Null;
    29.     }
    30.  
    31.     protected override void OnUpdate()
    32.     {
    33.         var physicsWorldSingleton = GetSingleton<PhysicsWorldSingleton>();
    34.         var collisionWorld = physicsWorldSingleton.CollisionWorld;
    35.  
    36.         var screenRay = Camera.main.ScreenPointToRay(Input.mousePosition);
    37.  
    38.         if (Raycast(collisionWorld, screenRay.origin, screenRay.GetPoint(1000)) != Entity.Null)
    39.         {
    40.             Debug.Log("cast");
    41.         }
    42.     }
    43. }
    44.  
     
  2. wrp8314

    wrp8314

    Joined:
    May 13, 2020
    Posts:
    6
    The problem disappeared after adding NetCodePhysicsConfig:)
     
  3. MaZhixin

    MaZhixin

    Joined:
    Dec 26, 2017
    Posts:
    1
    How do I add NetCodePhysicsConfig
     
  4. wrp8314

    wrp8314

    Joined:
    May 13, 2020
    Posts:
    6
    create a gameobject and add the "Net Code Physics Config" component to it, then check the LagCompensation checkbox and set the Client & Server History Size
     
    codeBatt, bb8_1 and NikiWalker like this.