I´ve got this C# script for my character´s movement. I´ve got no problem with moving right and left (if u think something is wrong tell me, i´m a beginner) but I don´t know how to make it jump slower, when I change it´s value it only changes the height it reaches.
Just a tip, generally people will not want to download your file to read it. You can paste the code directly into your post using code tags, or using the code buttons in the toolbar when you’re writing the post. You have a much easier time getting responses if everything is up front.
public class Player : MonoBehaviour {
public float speed = 500f;
public float jumpForce = 13000f;
bool canJump;
// Start is called before the first frame update
void Start() {
}
// Update is called once per frame
void Update() {
if (Input.GetKey(KeyCode.RightArrow)) {
gameObject.GetComponent<Rigidbody2D>().AddForce(new Vector2(speed * Time.deltaTime, 0));
gameObject.GetComponent<SpriteRenderer>().flipX = false;
}
if (Input.GetKey(KeyCode.LeftArrow)) {
gameObject.GetComponent<Rigidbody2D>().AddForce(new Vector2(-speed * Time.deltaTime, 0));
gameObject.GetComponent<SpriteRenderer>().flipX = true;
}
if (Input.GetKeyDown(KeyCode.UpArrow) && canJump) {
gameObject.GetComponent<Rigidbody2D>().AddForce(new Vector2(0, jumpForce * Time.deltaTime));
canJump = false;
}
}
private void OnCollisionEnter2D(Collision2D collision) {
if (collision.transform.tag == "ground") {
canJump = true;
}
}
}
Since you’re using physics, a jump’s motion will be a balance between the upward force of the jump and the downward force of gravity. Drag and mass also have an impact.
So if you want the jump motion itself to go slower, you need to reduce your jump force and also reduce your rigidbody2D’s gravity scale, or the world gravity force.