unity-game-engine3d2drigid-bodies

Why it is difference when use AddForce to make the character jumping in 2D and 3D game


I use a same script for both make character jump in 2D and 3D game:

using UnityEngine;
public class Test : MonoBehaviour
{
    private Rigidbody rb;
    public float jumpForce;
    private void Start()
    {
        rb = GetComponent<Rigidbody>();
    }
    private void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            rb.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
        }

    }
}

But in their result is very difference. I don't know how to show it through images so I make videos and upload them on Youtube: //use might like to mute if doesn't the music.

Here is the link of the 3D object jumping:

https://youtu.be/HWjPKYFaiL0

and there is 2D object is video:

https://youtu.be/w3HKmDRpKlQ

-2D object jump is just like suddenly appear in the air.

Although share a same scripts and Rigidbody but why it's difference between 2D and 3D.


Solution

  • The problem seems to be using different sized for the different projects, the 3D character is 1 unit big and the 2d is 5 units big.

    also the 3D environment is no the same as the 2D one, therefore you need to use Rigidbody 2D component instead