Skip to content

Commit 2634b45

Browse files
committed
fix wrong world being raycasted with
1 parent 6f3303a commit 2634b45

2 files changed

Lines changed: 11 additions & 9 deletions

File tree

source/Systems/PhysicsSystem.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,13 @@ readonly unsafe void ISystem.CollectMessageHandlers(MessageHandlerCollector coll
5959
[UnmanagedCallersOnly]
6060
private static StatusCode HandleRaycast(HandleMessage.Input input)
6161
{
62-
World world = input.world;
6362
ref PhysicsSystem system = ref input.ReadSystem<PhysicsSystem>();
6463
RaycastRequest raycast = input.ReadMessage<RaycastRequest>();
65-
ref PhysicsSimulatorSystem physicsSystem = ref system.systems.TryGetValue(world, out bool contains);
64+
ref PhysicsSimulatorSystem physicsSystem = ref system.systems.TryGetValue(raycast.world, out bool contains);
6665
if (!contains)
6766
{
68-
physicsSystem = new(world);
69-
system.systems.Add(world, physicsSystem);
67+
physicsSystem = new(raycast.world);
68+
system.systems.Add(raycast.world, physicsSystem);
7069
}
7170

7271
physicsSystem.PerformRaycastRequest(raycast);

tests/RaycastTests.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,19 @@ public class RaycastTests : PhysicsSystemsTests
1515
[Test]
1616
public unsafe void RaycastAgainstStaticFloor()
1717
{
18-
Body floorBody = new(world, new CubeShape(0.5f), BodyType.Static);
19-
Transform floorTransform = floorBody;
20-
floorTransform.LocalScale = new(100, 1, 1);
21-
floorTransform.LocalPosition = new(0, -2, 0);
18+
Body floorBody = new(world, new CubeShape(0.5f, 0.5f, 0.5f), BodyType.Static);
19+
floorBody.As<Transform>().LocalPosition = new(0f, -5f, 0f);
20+
floorBody.As<Transform>().LocalScale = new(100f, 1f, 1f);
2221

2322
simulator.Update(TimeSpan.FromSeconds(0.01f));
2423

24+
Vector3 origin = new(0.00013398135f, -4.000277f, 0.00049429137f);
25+
Vector3 direction = -Vector3.UnitY;
26+
float distance = 0.5f;
2527
using MemoryAddress temp = MemoryAddress.AllocateValue<(uint, bool)>(default);
2628
ref (uint entity, bool hit) result = ref temp.Read<(uint, bool)>();
27-
simulator.TryHandleMessage(new RaycastRequest(world, Vector3.Zero, -Vector3.UnitY, new(&HitCallback), 1.501f, (ulong)temp.Address));
29+
Assert.That(result.hit, Is.False);
30+
simulator.TryHandleMessage(new RaycastRequest(world, origin, direction, new(&HitCallback), distance, (ulong)temp.Address));
2831
Assert.That(result.hit, Is.True);
2932

3033
[UnmanagedCallersOnly]

0 commit comments

Comments
 (0)