protected override JobHandle OnUpdate(JobHandle inputDeps) { var headingTolerance = SimulationSettings.Instance.headingToleranceToAccelerate; return(Entities.ForEach((ref Rotation rotation, ref Movement movement, in MovementOrder movementOrder) => { // Accelerate only if orientation is within tolerance var fwd = math.forward(rotation.Value); var angle = PhysicsUtils.Angle(fwd, movementOrder.Heading); if (angle <= headingTolerance) { movement.Acceleration = math.normalize(fwd) * PhysicsUtils.GeesToMs2(movementOrder.AccelerationMagnitude); } }).Schedule(inputDeps)); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { var handle = Entities.ForEach((ref MovementOrder movementOrder, in InterceptTarget interceptTarget, in Position position, in Movement movement, in MovementCapabilities movementCapabilities) => { var intercept = PhysicsUtils.AccelerationToIntercept( new PhysicalState { Position = position.Value, Velocity = movement.Velocity, Acceleration = movement.Acceleration, }, new PhysicalState { Position = interceptTarget.Position, Velocity = interceptTarget.Velocity, Acceleration = interceptTarget.Acceleration, }, PhysicsUtils.GeesToMs2(movementCapabilities.MaxAccelerationMagnitude) ); movementOrder.Heading = math.normalize(intercept.Acceleration); movementOrder.AccelerationMagnitude = movementCapabilities.MaxAccelerationMagnitude; }).Schedule(inputDeps);