Ability to sit on a chair

Nixou

New member
Hello,
I have an issue trying to sit the character properly on a chair.
I'm working on the 2.3.1 version of Ultimate Character Controller on Unity 2020.3.2f1.

I created an interactable ability to sit on a chair object, activable pressing the F key when the character collides with a box around the chair. The character have 3 animations here: StandToSit, IDLE_Sit and SitToStand (the user make him stand up by pressing F a second time). Then my issue is with the character's capsule collider, it doesn't let the character put his buttocks on the chair: either he sits in front of the chair, with his feet on the floor and his buttocks flying, or the character is sits with his feet on the chair and his buttocks still flying above the chair. See those pictures because it's hard to explain:
Sit_InFrontOf_1.PNG Sit_Above_1.PNG

That I understand, this is because the character's capsule's height doesn't change during the StandToSit animation and the the bottom of the capsule is still touching the floor. The chair's collider and the capsule don't let the character to sit properly, as we can see on these picture:
Sit_InFrontOf_2.PNG
I tried to reduce the capsule height by calling an event during the StandToSit animation, but it doesn't work because apparently the capsule's height is constantly given by the CapsuleColliderPositioner.cs script and it keeps it high. For now I don't know how I could change or use this script to solve my collision problem. And of course I try to change back the capsule's size with another event during the SitToStand animation, but as far as the capsule's size doesn't change with my events, this is neither a success.

So please, if you see a clue to help me change the capsule height or solve this sitting issue in another way, I would be very grateful.
I'm a beginner on Ultimate Character Controller, so I would take any advice, thank you in advance for your kindness.
 
Last edited:
As DankP3 suggested, you could disable collisions entire during the animation, or set the chair to be on a physics layer which the character doesn't collide with.
 
Thank both of you for your answers !
By turning off the horizontal collisions during the animation, the character is now always sitting above the chair, not in front of it anymore.
And then if I pause the execution when he does it, and change the chair's layer, the character falls on the chair and sits properly.
The last point I have to solve now is: how to change the layer automatically during the animation, and change it back when he stands up.
Do you know how it is possible to do this ?
 
You can change a gameobject's layer easily with GameObject.layer = x. However changing layers during runtime can be risky if physics interactions depend on them. Instead of changing the object's layer, I would recommend using the state system to change the character's solid objects layer mask at the appropriate time (e.g. by activating a state when they start sitting, which would enable a state preset to change the layer mask).
 
Thank you very much for your answer.
Finally the problem was more or less solved only by deactivating the horizontal collisions and by having slightly reduce the size of the chair. Now when my character sits down he first teleports above the chair, then he sits up still floating above the chair, and finally when the animation to switch from standing to sitting is over, he " falls "into the chair, and is then properly seated. I get this result without touching the layers.
Likewise when he gets up, he first teleports above the chair, still in sitting position, then he stands up still floating above the chair, and finally when he has finished the animation to switch from sitting to standing, he is standing on the chair.
How do you think this problem could be fixed? Is it possible that this is still a layer issue, as the character manages to sit properly in the seat outside of the transition animations?
 
If you disable horizontal and vertical collisions then the character will not perform any collision detection. I would do that for this situation.
 
I had tried, if I turn off horizontal and vertical collisions, then the character sits in front of the chair, like before. So this solution does not work, but I had thought about it too.
 
You may need to adjust where the character moves to. With collisions disabled the character can move through objects. You can test this out with the Drive or Ride ability - that ability disables collisions so the character can interact with another object.
 
Top