- Home /
CharacterControllerMovement stuck
Hello, trying to work my character controller out, I can walk an everything but when I go into a wall or a collider the controllers position still moves and sometimes makes the character glitch right through the wall, any idea why this is so?
public class ThirdPersonPlayerMovement : MonoBehaviour
{
// Start is called before the first frame update
private CharacterController charController;
public float currentSpeed = 0;
void Start()
{
charController = GetComponent<CharacterController>();
}
// Update is called once per frame
void Update()
{
}
void FixedUpdate()
{
#region Movement -------------------------------------------
float hori = Input.GetAxis("Horizontal");
float vert = Input.GetAxis("Vertical");
Vector3 move = new Vector3(hori, 0, vert);
move = this.transform.TransformDirection(move);
charController.Move(move * currentSpeed * Time.deltaTime);
#endregion
}
}
i'm not sure if this is the case but normally when that glitch is happening its because only one of the objects has a collider and both need it OR there's a rigidbody missing on one of the objects (not necessary on both).
usually some type of combination of those 2 issues.
The Character Controller is often used in the Update()
method. But I don't find significant difference if it is inside the FixedUpdate()
On the other hand, your Inputs calls should be in the Update()
for sure. Other wise you will miss some Input eventually. I would say that this is a possible cause for your problems.
Not related to you question, but I suffered a bit with it: You need to apply gravity to your character 100% of the time. Otherwise the isGrounded()
method turns very unreliable.
thanks for your replys, sadly I still havnt figured out the problem even with your tips. its really odd.. I didnt have the trouble when I tried out the movement with transfrom.
Try using Time.fixedDeltaTime ins$$anonymous$$d of Time.DeltaTime.
Delta time gives you the period of the last frame, but your instructions are on the fixedUpdade, sou you should correct it using the period of the fixed update.
That is the only thing I can think of.
It didn't really do much either, thanks for taking the time to try help me, I see if I can find the problem with more google searches.
Hi, how did you set up your colliders? Do you have a appropriately sized collider? Did you check if some of them may be trigger? Did you change your characters collider to continous ins$$anonymous$$d of discrete?