using UnityEngine;
public class miscare : MonoBehaviour
{
[SerializeField] private string horizontalInputName;
[SerializeField] private string verticalInputName;
[SerializeField] private float movementSpeed;
private CharacterController charController;
private void Awake()
{
charController = GetComponent<CharacterController>();
}
private void Update()
{
PlayerMovement();
}
private void PlayerMovement()
{
float vertInput = Input.GetAxis(verticalInputName) * movementSpeed;
float horizInput = Input.GetAxis(horizontalInputName) * movementSpeed;
Vector3 forwardMovement = transform.forward * vertInput;
Vector3 lateralMovement = transform.right * horizInput;
charController.SimpleMove(forwardMovement + lateralMovement);
}
}
What isn’t working? Do you get an error message?
Please edit your post and add code-tags:
no i didn’t get an error mesage
Then it works perfectly.
If you think it behaves wrongly, what’s the intended behaviour, and what’s the actual behaviour?
2 Likes
Have you attached the script to your character controller gameObject? Is there any change in the transform of character controller gameObject?