Character Controller only works once turned off and on again
I know that sounds like a joke, like if it's not working just turn it off and on again but that's where I'm at.
My character controller will not work unless I disable it in the inspector and then enable it again. I don't know how I achieved this bug because it used to work fine.
I don't know if anyone can help me with this because it seems so strange, but I'm really not sure where to start so if anyone knows anything about this type of issue I'd appreciate any insight whatsoever.
-Thanks in advance
Are you using https://docs.unity3d.com/ScriptReference/CharacterController.html or some custom / self made one controller ?
If it's the one from that link, then you are probably getting a reference to it somewhere and calling controller.$$anonymous$$ove(..) , right ?
Could it be that either the Controller or whatever you are feeding to $$anonymous$$ove(...) aren't working properly ?
It would help if you could show us the code how you're using it as it would help us help you :)
Answer by nolan_oc · Jun 24, 2020 at 03:33 AM
Hi thanks for the response @ShadoX !
Sorry about that, It's a script i typed out after watching some tutorials and it goes a little something like this.
I added an on start disable and then enable character controller so it's working again but it bothers me that I did that, feels very sloppy to just patch it instead of fixing the problem you know?
public class CharacterController : MonoBehaviour
{
public float moveSpeed = 5f;
public Rigidbody2D body;
Vector2 movement;
public Animator animator;
void Update()
{
//This handles which animation should play for character
movement.x = Input.GetAxisRaw("Horizontal");
movement.y = Input.GetAxisRaw("Vertical");
animator.SetFloat("Horizontal", movement.x);
animator.SetFloat("Vertical", movement.y);
animator.SetFloat("Speed", movement.sqrMagnitude);
}
private void FixedUpdate()
{
//this handles the actual physical movement of player
body.MovePosition(body.position+movement * moveSpeed * Time.fixedDeltaTime);
}
}
Your answer
Follow this Question
Related Questions
Error CS0103 0 Answers
I want to make an on click movement script with a grid type map need references to look at 0 Answers
infamous first light run code help 1 Answer
Trying to figure out WallRiding, with Vector3.Cross 0 Answers
Character controller for fixed perspective camera (moving relative to arbitrary point on screen) 0 Answers