Question by
Twinklier · Jul 22, 2018 at 11:23 AM ·
character controllerspeed issues
Character Controller moves slow?
Player walks so slow, sometimes doesn't even walk. Jump is impossible. Altering speed doesn't do anything. Help ;(
void Start () {
characterController = GetComponent<CharacterController>();
}
void Update () {
transform.eulerAngles = Vector3.zero + (Vector3.up * camRotY);
{
moveDir = new Vector3(Input.GetAxis("Horizontal"), verticality, Input.GetAxis("Vertical"));
moveDir = transform.TransformDirection(moveDir);
characterController.Move(moveDir * Time.deltaTime);
moveDir *= speed;
if (!characterController.isGrounded)
{
if (verticality < 0)
verticality *= 1.01f;
verticality -= Time.deltaTime * 6;
camera_wobble.cullingMode = AnimatorCullingMode.CullCompletely;
}
if (characterController.isGrounded)
{
if (Input.GetAxis("Jump") != 0 && slope_angle < characterController.slopeLimit)
verticality = 1.8f;
verticality = 0;
//cam wobble, no movements here
{
if (moveDir != Vector3.zero + (moveDir.y * Vector3.up) && slope_angle < characterController.slopeLimit)
camera_wobble.cullingMode = AnimatorCullingMode.AlwaysAnimate;
else
{
camera_wobble.cullingMode = AnimatorCullingMode.CullCompletely;
Camera.localPosition =
new Vector3(Mathf.Lerp(Camera.localPosition.x, 0, Camera.localPosition.x * 0.2f),
Mathf.Lerp(Camera.localPosition.y, 0, Camera.localPosition.y * 0.2f),
Mathf.Lerp(Camera.localPosition.z, 0, Camera.localPosition.z * 0.2f));
}
}
}
}
//cam rot, no movements here
{
camRotX -= Input.GetAxis("Mouse Y") * sensitivity * 0.8f;
camRotY += Input.GetAxis("Mouse X") * sensitivity;
camRotX = Mathf.Clamp(camRotX, -90, 90);
Camera.eulerAngles = new Vector3(camRotX, camRotY, 0);
}
}
void OnControllerColliderHit(ControllerColliderHit hit)
{
slope_angle = Vector3.Angle(Vector3.up, hit.normal);
}
}
I was trying to make the player moves horizontally slower while in air, so I put the moveDir *= speed into the .isGrounded and ! .isGrounded brackets and adjust each from there. That's when the problem occur. I move it back to where it was and the problem isn't gone.
Help? Please ; (
have-a-look.png
(19.1 kB)
Comment
Good day.
Look at this part of code:
characterController.$$anonymous$$ove(moveDir * Time.deltaTime);
moveDir *= speed;
Yopu first move the player, and then apply the speed.... of course changing speed does nothing... you are pplying the speed after moving... each frame..
Change the order of that 2 lines.