Answer the question
In order to leave comments, you need to log in
How to make jump and fall speed the same?
I'm making a 2d platformer. Rigidbody2d hangs on the character. You need to make a move.
The jump is implemented with rb.AddForce(Vector2.up * jump_power); where rb is a rigidbody and jump_power is a public float.
The character jumps, but jumps low. By setting the jump_power value, I was able to ensure that the character jumps to the desired height, however, he does it abruptly, and falls very slowly. After playing around with the gravity and mass values, I achieved a normal fall speed, but this does not affect the jump speed. Can you tell me how can I change the code to solve this problem?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMove : MonoBehaviour {
private Rigidbody2D rb;
public float move_speed = 10.0f;
public float jump_power = 4000f;
void Start() {
rb = GetComponent<Rigidbody2D>();
}
void Update() {
float moveX = Input.GetAxis("Horizontal");
rb.MovePosition(rb.position + Vector2.right * moveX * move_speed * Time.deltaTime);
if (Input.GetKeyDown(KeyCode.Space))
rb.AddForce(Vector2.up * jump_power);
}
}
rb.velocity = new Vector2(moveX * move_speed, rb.velocity.y);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question