Hey, everyone! I am trying to create a player that can only go up certain slopes and if the slope is too steep they will slide down it and slide at a speed that is higher in relation to the intensity of the slope.
So far all I have is the character moving and can go up certain slope limits using the character controller but I have no idea where to start with the sliding. I have done some research but still do not understand it and could find nothing that really helped.
Below is what I have so far for movement.
Thanks, all in advance for helping!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour {
public float moveSpeed;
public CharacterController controller;
private Vector3 moveDirection;
public float gravityScale;
// Use this for initialization
void Start () {
controller = GetComponent<CharacterController>();
}
// Update is called once per frame
void Update () {
moveDirection = new Vector3(Input.GetAxis("Horizontal") * moveSpeed, 0f, Input.GetAxis("Vertical") * moveSpeed);
moveDirection.y = moveDirection.y + (Physics.gravity.y * gravityScale);
controller.Move(moveDirection * Time.deltaTime);
}
}