As the title suggests, I use this script for jump with the object, but when it jumps, jump and it drops bad, jerky, not fluid, as if gravity is not added well.
public float gravity = 20.0f;
public float jumpSpeed = 8.0f;
private Vector3 movement;
void Start()
{
Controller = GetComponent<CharacterController>();}
float Horizontal = Input.GetAxis("Horizontal");
float Vertical = Input.GetAxis("Vertical");
movement = (transform.right * Horizontal + transform.forward * Vertical) * speed;
if (Controller.isGrounded && Input.GetKeyDown(KeyCode.Space)){
movement.y = jumpSpeed;}
movement.y -= gravity * Time.deltaTime;
Controller.Move(movement * Time.deltaTime);
This is a different script that I have used before and know works. You need a character controller and rigidbody for it to work. This is the link to the script: https://docs.unity3d.com/ScriptReference/CharacterController.Move.htm?_ga=2.112896065.410999767.1589732785-1327862508.1586352632
public class example : MonoBehaviour {
//Variables
public float speed = 6.0F;
public float jumpSpeed = 8.0F;
public float gravity = 20.0F;
private Vector3 moveDirection = Vector3.zero;
void Update() {
CharacterController controller = GetComponent<CharacterController>();
// is the controller on the ground?
if (controller.isGrounded) {
//Feed moveDirection with input.
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
//Multiply it by speed.
moveDirection *= speed;
//Jumping
if (Input.GetButton("Jump"))
moveDirection.y = jumpSpeed;
}
//Applying gravity to the controller
moveDirection.y -= gravity * Time.deltaTime;
//Making the character move
controller.Move(moveDirection * Time.deltaTime);
}
}