- Home /
How I make the Character move smooth on terrain?
When I move the character on the terrain it walks roughly in contrast of plane which it walks smoothly on it
I use Character controller to move my character
The player movement code:
#pragma strict
var gravity : float = 9.8;
var speed : float = 10;
var jumpSpeed : float = 0.3;
var moveDirection : Vector3 = Vector3.zero;
function Start () {
}
function Update () {
var controller : CharacterController = GetComponent(CharacterController);
transform.Rotate(0, 2 * Input.GetAxis("Mouse X"),0);
if(controller.isGrounded){
moveDirection.x = 0;
moveDirection.z = 0;
if(Input.GetKey("up")){
moveDirection = transform.TransformDirection(Vector3.forward)* 5;
controller.Move(moveDirection * Time.deltaTime * speed);
animation.Play("walk");
}
if(Input.GetKey(KeyCode.Space)){
moveDirection = transform.TransformDirection(Vector3.forward)* 4;
controller.Move(moveDirection * Time.deltaTime * speed);
animation.Play("run");
}
if(Input.GetKeyUp(KeyCode.Space)){
animation.Play("idle");
}
if(Input.GetKey("down")){
moveDirection = -transform.TransformDirection(Vector3.forward)* 2;
controller.Move(moveDirection * Time.deltaTime * speed );
animation.Play("walk");
}
}
moveDirection.y -= gravity*Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
}
does the terrain have colliders on it? That would make the player walk awkwardly on it. Try removing the collision boxes.
Yes sure it has terrain collider, but which collision boxes u mean to remove ??
are you using a character controller? you should put more time and effort into your question if you hope for a useable answer, provide the relevant details!
I'm not really sure, which is why I didn't put it as an answer. Are you talking about trees and shrubs? You would want collision boxes on those to keep players from walking into/through them. Or, are you talking about some gravel or something like that? In that case, I would suggest disabling the collision boxes so that Unity treats that area as a plane (just like a normal plane you are walking on, except it has a rock texture)
I am talking about the terrain itself the land, but I can not find any box colliders , or you would tell me how to make it like a plane to make the player moves smoothly
Your answer

Follow this Question
Related Questions
Camera Colliding with Terrain 1 Answer
How to object moving follow the terrian? 0 Answers
Moving along surface without physics? 1 Answer
Make a simple tree 1 Answer
Walls not moving in 1 Answer