Reputation: 29
I made a cube a trigger with no material renderer and when I played and walked my player into it, my player could not move and Unity said that "Character.Controller.Move called on inactive controller" `using UnityEngine;
public class PlayerMove : MonoBehaviour { [SerializeField] private MoveSettings _settings = null;
private Vector3 _moveDirection;
private CharacterController _controller;
private void Awake()
{
_controller = GetComponent<CharacterController>();
}
private void Update()
{
DefaultMovement();
}
private void FixedUpdate()
{
_controller.Move(_moveDirection * Time.deltaTime);
//this is where the error is
}
private void DefaultMovement()
{
if (_controller.isGrounded)
{
Vector2 input = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));
if (input.x != 0 && input.y != 0)
{
input *= 0.777f;
}
_moveDirection.x = input.x * _settings.speed;
_moveDirection.z = input.y * _settings.speed;
_moveDirection.y = -_settings.antiBump;
_moveDirection = transform.TransformDirection(_moveDirection);
if (Input.GetKey(KeyCode.Space))
{
Jump();
}
}
else
{
_moveDirection.y -= _settings.gravity * Time.deltaTime;
}
}
private void Jump()
{
_moveDirection.y += _settings.jumpForce;
}
}`
im also new so please help!
Upvotes: 0
Views: 297
Reputation: 46
Are you sure it is enabled in editor (the little checkbox on every component). If you want to make sure it's enabled add this line to Awake
method
_controller.enabled = true;
Upvotes: 0