Hi,
I have a very simple character controller movement script and it works fine except when i am supposed to run downhill. The player starts hopping down the slope and i would like it to walk normally. I have looked for a solution and found that it might be raycasting but i cant seem to make i work properly… The most promising i found is this https://forum.unity.com/threads/player-character-movement-jumps-when-moving-down-the-slopes.497911/ but when i try to incorporate it in my script it doenst do what i want (so basically i don’t understand what makes that solution work). Can anyone help?
Here is my script
public class PlayerMovement : MonoBehaviour {
public float Speed = 5.0f;
public float JumpSpeed = 7.0f;
public float TurnSpeed = 3.0f;
public float gravity = 20.0f;
private Vector3 moveDirection = Vector3.zero;
private CharacterController controller;
void Start () {
controller = GetComponent<CharacterController>();
}
// Update is called once per frame
void FixedUpdate () {
transform.Rotate(0, Input.GetAxis("Horizontal") * TurnSpeed, 0);
if (controller.isGrounded) {
moveDirection = new Vector3(0, 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= Speed;
if (Input.GetButton("Jump")) {
moveDirection.y = JumpSpeed;
}
} else {
moveDirection.y -= gravity * Time.deltaTime;
}
controller.Move(moveDirection * Time.deltaTime);
}
}