- Home /
I have a little cube that jumps and moves but when it jumps it falls down too slowly. How can i make it fall down faster while still jumping as high?
playerController script:
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class PlayerController : MonoBehaviour { private Rigidbody playerRb; public float speed; public float jumpForce;
// Start is called before the first frame update
void Start()
{
playerRb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void FixedUpdate()
{
float horizontalInput = Input.GetAxisRaw("Horizontal");
playerRb.velocity = new Vector2(horizontalInput * speed, playerRb.velocity.y);
}
private void Update()
{
if (Input.GetButtonDown("Jump"))
{
playerRb.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
}
}
}
Answer by Llama_w_2Ls · Jan 12, 2021 at 07:14 PM
You can increase the gravity settings by going in the Unity Editor, look at the menu at the top, Edit -> Project Settings -> Physics -> (at the top) Gravity and you can increase its value.
I would recommend setting the y velocity of your rigidbody when jumping. For example:
public float JumpForce;
void Update()
{
if (Input.GetButtonDown("Jump"))
{
playerRb.velocity = new Vector3
(
playerRb.velocity.x,
playerRb.velocity.y * JumpForce,
playerRb.velocity.z
);
}
}
This would ensure your jump height isn't dependant on the mass of your object.
Your answer
Follow this Question
Related Questions
Why does my character keep falling? 6 Answers
Jumping, falling, and landing animations. 1 Answer
Falling off respawn 4 Answers
Particles falling/pushing through walls 0 Answers