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. Join us on Thursday, June 8, for a Q&A with Unity's Content Pipeline group here on the forum, and on the Unity Discord, and discuss topics around Content Build, Import Workflows, Asset Database, and Addressables!
    Dismiss Notice

Question PhysicsWorld.ApplyLinearImpulse is not working

Discussion in 'Physics for ECS' started by SocttJame, Mar 17, 2023.

  1. SocttJame

    SocttJame

    Joined:
    Dec 11, 2017
    Posts:
    5
    Hi! I have some issue with the following code:
    Code (CSharp):
    1. using System;
    2. using Code.QTry.Components;
    3. using Unity.Entities;
    4. using Unity.Mathematics;
    5. using Unity.Physics;
    6. using Unity.Physics.Extensions;
    7. using Unity.Physics.Systems;
    8. using UnityEngine;
    9.  
    10. namespace Code.QTry.Systems
    11. {
    12.     [UpdateInGroup(typeof(FixedStepSimulationSystemGroup))]
    13.     [UpdateAfter(typeof(PhysicsInitializeGroup))]
    14.     [UpdateBefore(typeof(PhysicsSimulationGroup))]
    15.     [RequireMatchingQueriesForUpdate]
    16.     public partial class ClickKeyAndAddImpulseSystem : SystemBase
    17.     {
    18.         protected override void OnUpdate()
    19.         {
    20.             if (!Input.GetKey(KeyCode.Space))
    21.                 return;
    22.             var world = SystemAPI.GetSingletonRW<PhysicsWorldSingleton>();
    23.             var deltaTime = SystemAPI.Time.fixedDeltaTime;
    24.             CompleteDependency();
    25.             foreach (var (clickKeyAndAddImpulse, entity) in SystemAPI.Query<RefRO<ClickKeyAndAddImpulse>>()
    26.                          .WithEntityAccess())
    27.             {
    28.                 var impulse = new float3(0f, 0f, 1f) * 10f * deltaTime;
    29.                 var index = world.ValueRW.PhysicsWorld.GetRigidBodyIndex(entity);
    30.                 world.ValueRW.PhysicsWorld.ApplyLinearImpulse(index, impulse);
    31.             }
    32.         }
    33.     }
    34. }
    I run the game and nothing happen when i click <space>. The package i use is Unity.Physics 1.0.0-pre.44

    Help! >...<
     

    Attached Files: