I am currently working on my character's movement in Unity3D. I managed to make him move relatively to the mouse cursor.
I set a slope limit of 45°, which does not allow the character to walk up the mountains with higher degrees. But he can still jump them up.
How do I manage to make him slide down again when he jumped at places with too high slope?
Thanks in advance.
edit: Code snippet of my basic movement.
using UnityEngine;
using System.Collections;
public class BasicMovement : MonoBehaviour {
private float speed;
private float jumpSpeed;
private float gravity;
private float slopeLimit;
private Vector3 moveDirection = Vector3.zero;
void Start()
{
PlayerSettings settings = GetComponent<PlayerSettings>();
speed = settings.GetSpeed();
jumpSpeed = settings.GetJumpSpeed();
gravity = settings.GetGravity();
slopeLimit = settings.GetSlopeLimit();
}
void Update() {
CharacterController controller = GetComponent<CharacterController>();
controller.slopeLimit = slopeLimit;
if (controller.isGrounded) {
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
if (Input.GetButton("Jump")) {
moveDirection.y = jumpSpeed;
}
}
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
}
}