- Home /
Move character woth ground moving
I have a character (that has character controller) and a ground (that has animations to move up and down and left and right)
I want to when character is on ground, move with ground (and go up and .... With ground)
How can i do that?
Answer by Jeremy Hindle · Feb 15, 2013 at 08:17 AM
First detect if the character is touching the ground. I would personally do this with a raycast being drawn from your character downwards.
Then, if the character is touching the moving ground (you could tag the specific GameObject) then add the Vector3 transform which is occurring to the platform to the character.
If you would like a more detailed answer please let me know and I can write up an example when I have time.
thank you. i am new to unity, can you example me? this is my code: var controller : CharacterController = GetComponent(CharacterController); if( controller.isGrounded){
movedir = Vector3 (-Input.GetAxis ("Vertical"),0,Input.GetAxis ("Horizontal"));
movedir = transform.TransformDirection(movedir);
movedir*= mspeed ;
if (Input.Get$$anonymous$$eyDown ("space")) {
movedir.y +=jspeed;
}
}else {
movedir = Vector3 (-Input.GetAxis ("Vertical"),movedir.y,Input.GetAxis ("Horizontal"));
movedir = transform.TransformDirection(movedir);
movedir.z *= mspeed;
movedir.x *= mspeed;
}
movedir.y -= gravity * Time.deltaTime;
controller.$$anonymous$$ove(movedir * Time.deltaTime);
Your answer
![](https://koobas.hobune.stream/wayback/20220613092730im_/https://answers.unity.com/themes/thub/images/avi.jpg)