using Physics.Components; using Unity.Burst; using Unity.Entities; using Unity.Transforms; using UnityEngine; namespace Physics.Systems { [UpdateInGroup(typeof(FixedStepSimulationSystemGroup))] [UpdateBefore(typeof(PhysicsSystem))] public partial struct PhysicsSystem : ISystem { [BurstCompile] public void OnCreate(ref SystemState state) { } [BurstCompile] public void OnUpdate(ref SystemState state) { foreach (var (particle, transform, entity) in SystemAPI.Query, RefRW>().WithEntityAccess() ) { particle.ValueRW.PreviousPosition = transform.ValueRO.Position; particle.ValueRW.Velocity += particle.ValueRO.Acceleration * SystemAPI.Time.DeltaTime; transform.ValueRW.Position += particle.ValueRO.Velocity * SystemAPI.Time.DeltaTime; particle.ValueRW.Acceleration = 0; Debug.DrawLine(particle.ValueRO.PreviousPosition, transform.ValueRO.Position, Color.red, 10f); } } [BurstCompile] public void OnDestroy(ref SystemState state) { } } }