(Case 951618) Physics: Raycast hits ghost collider

Physics.Raycast hits colliders at their position from during scene activation, even when those non-static objects have been moved to another location.

Please see the provided video, that shows how Physics.Raycast used to work in 2017.1 and how it does work in 2017.2.0b11.

Reproduce

  1. Open user attached project in Unity 2017.1.1p2

  2. Open Assets/Scene.unity

  3. Press Play
    Observe the line that represents the raycast and the red sphere that represents the hit point.

  4. Move ‘Player’ GameObject around
    Observe the player capsule does not get hit if the raycast does not intersect it.

  5. Open project in Unity 2017.2.0b11

  6. Repeat from Step 2.
    Observe the player capsule is hit even if the raycast does not intersect it.

Expected
‘Ghosting colliders’ should not be hit.

Does the problem occur when moving with CharacterController.Move()?

Thanks for the idea, just tested it!

It does occur when using CharacterController.Move() as well.
It does not occur when I remove the CharacterController and add a CapsuleCollider instead and write to transform.position.

I should also mention that I turned off the auto-sync features.

Physics.autoSimulation = false;
Physics.autoSyncTransforms = false;

Turning on Physics.autoSimulation fixes the issue. But I wonder why does it work with a Collider in either mode, but not with a CharacterController.

3225228–247374–Case_951618_Physics_Raycast_hits_ghost_collider.zip (22.8 KB)

A character controller is raycast based so it would need the physics bodies to be refreshed before the raycast occurs, does that sound similar?

Here is the reply from QA:

Many things for providing an explanation!

1 Like

Yep thought that would be the case. They should make sure that they update the physics viz if they aren’t already, and draw colliders for things where they logically are rather than where the mesh appears to be.

I’m sure they thought of that. Right? I hope. In any case someone should think about updating the physics vis or a lot more reports like this will be soaking up QA time.

1 Like

What I actually don’t really understand is this:

I have a hard time wrapping my head around this, because If I understand MelvMay’s reply regarding autoSyncTransforms correctly, Unity does do a sync always, no matter whether autoSyncTransforms is set to true or false. The only difference seems to be when this happens.

My thought is or was, because Unity does seem to sync transforms even with autoSyncTransforms set to false, the CharacterCollider changes on the transform should find their way over to the physics engine. But they don’t seem to, which is why I submitted the bug-report. :face_with_spiral_eyes:

Well that’s 2D and this is Physx, so maybe it doesn’t happen with Physx? @yant @MelvMay
Would be nice to have some tips or ref I can advise or help forum users with :slight_smile:

1 Like

Here’s my guess: the SyncTransforms that is always called once per fixed update even when autoSyncTransforms = false is actually called by the Physics.Simulate that is internally called when autoSimulation is true

Edit: I’d be curious to see what happens if you set both autoSyncTransforms and autoSimulation to false but call Physics.SyncTransforms manually once per frame in your example project

1 Like

Hey. I commented the fogbugz case, but putting something similar here, for better transparency.

So the CharacterController is actually two things in one internally, in PhysX. It’s both a shape (ie Collider in Unity-speak) and a kinematic actor (ie Rigidbody with “isKinematic” set). Calling CharacterController::Move results in something similar to Rigidbody::MovePosition really, and the result of that is only available after a simulation was run. In this project, the simulation is never run (Physics.autoSimulation=false), and nothing is calling Physics.Simulate() either. That’s why the CC’s shape doesn’t happen to be where you expect.

1 Like

Thanks for the reply.

I wonder why does it work if I remove the CC and add a Capsule Collider then? In this case, it’s still Physics.autoSimulation=false and Physics.Simulate() isn’t called either, but the Capsule Collider position if where you’d expect it.

That’s because a builtin-in collider doesn’t include a hidden implicit kinematic actor, so its pose is reflected as soon it’s been written to.

1 Like