Hello There!
i recently staretd devloping a game, set in a top down isometric perspective. Since i dont need physics, i decided to go with a character controller for movement. and it works great movement wise! however, whenever the player object moves across a slope, it goes up, but then stays upo there, even if theres nothing underneath it. i dont udnerstand why. i did something similar before, and back then it did fall down. any1 know anything?
heres the movement script:
using UnityEngine;
using UnityEngine.InputSystem;
public class PlayerMovement : MonoBehaviour
{
public float moveSpeed = 5f;
public float rotationSpeed = 10f;
private CharacterController controller;
private Vector2 moveInput;
private Camera mainCamera;
private Animator animator;
private void Start()
{
controller = GetComponent<CharacterController>();
mainCamera = Camera.main;
animator = GetComponent<Animator>();
}
public void OnMove(InputAction.CallbackContext context)
{
moveInput = context.ReadValue<Vector2>();
}
private void Update()
{
Vector3 move = new Vector3(moveInput.x, 0, moveInput.y);
Vector3 moveDirection = mainCamera.transform.TransformDirection(move);
moveDirection.y = 0;
controller.Move(moveDirection.normalized * moveSpeed * Time.deltaTime);
if (moveDirection != Vector3.zero)
{
Quaternion targetRotation = Quaternion.LookRotation(moveDirection);
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, rotationSpeed * Time.deltaTime);
}
animator.SetBool("isRunning", moveDirection != Vector3.zero);
}
}