- Home /
Unity 3D: When walking off of object character falls almost instantly
When jumping the falling is fine but if I just walk off of a cube the character falls instantly. Here's my movement script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Control : MonoBehaviour
{
public float moveSpeed;
public float jumpForce;
public CharacterController controller;
private Vector3 moveDirection;
public float gravityScale;
// Start is called before the first frame update
void Start()
{
controller = GetComponent<CharacterController>();
}
// Update is called once per frame
void Update()
{
Input.GetAxis("Vertical") * moveSpeed);
float yStore = moveDirection.y;
moveDirection = (transform.forward * Input.GetAxis("Vertical") ) + (transform.right * Input.GetAxis("Horizontal"));
moveDirection = moveDirection.normalized * moveSpeed;
moveDirection.y = yStore;
if (controller.isGrounded)
{
if (Input.GetButtonDown("Jump"))
{
moveDirection.y = jumpForce;
}
}
moveDirection.y = moveDirection.y + (Physics.gravity.y * gravityScale * Time.deltaTime );
controller.Move(moveDirection * Time.deltaTime);
}
}
Answer by agior312 · Apr 20, 2020 at 08:03 PM
I can see a moveDirection.y that is assigned as Physics.gravity.y * gravityScale
Physics.gravity.y should be something like -9.8 by default, so you're multipling your gravityScale (I suppose it's 1) for -9.8. And as it is in the update method you're doing this multiplication about 60 times per second
Your answer
![](https://koobas.hobune.stream/wayback/20220612231925im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How can i make my character jump and slide on command? 0 Answers
how to make automatic gradual acceleration 1 Answer
My movement script is kind of broken for jumping (upward force is diminished after first jump) 1 Answer
sonic movement stick to the ground 1 Answer
How to make a top down character snap to different directions 0 Answers