Created
April 4, 2020 15:12
-
-
Save jeffvella/fc9e674b7edd02e8a343929256087764 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| protected override void OnUpdate() | |
| { | |
| var collisionEvents = _collisionEvents; | |
| var detectors = _buffer; | |
| detectors.Clear(); | |
| Entities.ForEach((Entity entity, ref CollisionDetector detector, in Translation pos, in OwnerRef owner) => | |
| { | |
| detectors.Add(new DetectorInfo | |
| { | |
| Entity = entity, | |
| Position = pos.Value, | |
| Range = detector.Range, | |
| Owner = owner | |
| }); | |
| }).Run(); | |
| Entities.WithNone<CollisionDetector>().ForEach((Entity entity, ref ActorDefinition def, ref Translation pos) => | |
| { | |
| for (int i = 0; i < detectors.Length; i++) | |
| { | |
| var detector = detectors[i]; | |
| var distance = math.distance(detector.Position, pos.Value); | |
| if (distance < detector.Range) | |
| { | |
| collisionEvents.Enqueue(new CollisionEvent | |
| { | |
| Source = detector, | |
| Hit = new Hit | |
| { | |
| Position = detector.Position + (pos.Value - detector.Position), | |
| Target = entity | |
| }, | |
| }); | |
| } | |
| } | |
| }).WithReadOnly(detectors).WithoutBurst().Run(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment