How to disable/enable all kind of collision and physics to UCC characters?

Hello,

I'm looking for a way to disable and then enable the collision and physics to my ucc characters through code. In one of my levels, Im literally stacking characters on top of each other and I use the locomotion script method for changing position and rotation, but now they hit each other and they aren't on the exact same position / rotation.
 

Andrew

Moderator
Staff member
In the character's UltimateCharacterLocomotion, you can use a state preset to adjust any of its Physics values, like Detect Horizontal/Vertical Collisions, Collider Layer Mask, etc.
 
The problem is that I call

_ultimateCharacterLocomotion.SetPositionAndRotation(newTransform.position, newTransform.rotation);


and at that point the character still hasn't entered the new state so the physics are still on, maybe I should enter the state and then change position and rotation or do all of that through code before calling SetPositionAndRotation
 
Last edited:

Andrew

Moderator
Staff member
It would be best to set the new state, then wait at least until the current FixedUpdate cycle has ended before forcing a transform update.
 
I still can't get this to work even if I disable them through code and then set position and rotation it takes some time to disable them and the time is around 0.5 seconds which is a lot

C#:
       public void ChangeTransform(Transform newTransform)
        {
            _ultimateCharacterLocomotion.DetectHorizontalCollisions = false;
            _ultimateCharacterLocomotion.DetectVerticalCollisions = false;
            _ultimateCharacterLocomotion.UseGravity = false;
            StartCoroutine(ChangeTransformRoutine(newTransform));
        }

        private IEnumerator ChangeTransformRoutine(Transform newTransform)
        {
            yield return new WaitForSeconds(0.5f);
            _ultimateCharacterLocomotion.SetPositionAndRotation(newTransform.position, newTransform.rotation, false, false);
        }


This works, but it's really bad with that long interval I want max 0.05 seconds otherwise it seems laggy.
 

Andrew

Moderator
Staff member
Have you tried just using SetState to enable a state preset that disables collisions, then in the next FixedUpdate tick run SetPosition?
 
Yes, but even after calling

_ultimateCharacterLocomotion.SetState("MyState",true);

and then waiting for the FixedUpdate it wont work properly, I have to wait a couple of frames so for now the half baked solution is to start setting the position inside Fixed update every frame for the next 0.5 seconds. If there are no other options I may spawn a particle effect to get rid of the slight jitter.
 

Andrew

Moderator
Staff member
I'm not sure if there are any more efficient solutions to be honest, quickly enabling/disabling all physics collisions on the fly is not a common use case. Maybe you could try a non-UCC approach, e.g. disabling the character's CapsuleCollider?
 
Top