- Home /
Sit in chair stumped on how to position
I know how to make the animation fire for the trigger, but I can't for the life of me figure out how to set a position.
The problem:
I have a chair that has a collision state to it. When the person comes up they bump in to the chair and are supposed to sit.
What happens is that they come up and sit... In mid air.
I need to know (or point me in the right direction) of how to set the position for the animation. I'm still a beginner, but I'm learning fairly quickly. This problem has been illusive, though. I know there was a way to do it in Legacy, but now I'm using mecanim.
If anyone knows how this can be done... Please help.
So what's the problem here?
Your character animation is good or bad?
Can you not freeze the chair's Y axis so it doesn't move up or down just to the side?
$$anonymous$$y character animation is good. It will sit. The chair is fine. The problem is that when it collides the character sits, but not in the chair. I need to know how to make a character go to a position. How to set X, Y, Z by scripting. I'm not sure how to do it.
Answer by cjdev · Aug 13, 2015 at 09:05 PM
Sounds like Animator.MatchTarget might be what you're looking for.
How do you achieve this? I'm using $$anonymous$$ecanim. The chair doesn't have any sort of animation on it. I'm not sure how matchtarget works. Would you put code in the chair? On the player? I'm sorry for being a bit of a noob when it comes to this. I thought there was a way to just add the x, y, and z to my current script to tell the player model where to sit.
If I understand what you're trying to do, I think you can use Target $$anonymous$$atching to transition the sitting animation of the player to the position and rotation it needs to be to look right (you could use an empty game object in the editor and just use the transform).
Go into scene view when the 'sit in mid air' happens, click on the Player's CController (assu$$anonymous$$g player has one) and see where that CC collider is. I suspect you'll find the bottom of the CC capsule collider is in the chair seat with the player in the middle of it (thus sitting in mid air).
The player controller is mecanim. The code I have in the chair now for attempting to match the height and everything is
other.gameObject.transform.position = gameObject.transform.position;
It appears to work somewhat, but now sits on the back of the chair ins$$anonymous$$d of down on the chair. other.gameObject refers to the player and gameObject is the cube that I'm attempting to use for this experiment.
$$anonymous$$ecanim is not a player controller, at least in the classic sense. Are you saying you do not use a CharacterController object on the player, you move him with physics forces or your own? If you DO have a CC, do what I asked and maybe take a screenshot, let's see where your CC is in this scenario.
Your answer
![](https://koobas.hobune.stream/wayback/20220611235649im_/https://answers.unity.com/themes/thub/images/avi.jpg)