Unity 2d jumping script

后端 未结 3 1850
北恋
北恋 2021-01-02 01:37

Does anyone have a good jumping script for 2d games in unity? The code I have works but still is far from jumping, it looks like it is flying.

using UnityEng         


        
3条回答
  •  青春惊慌失措
    2021-01-02 02:02

    Use Addforce() method of a rigidbody compenent, make sure rigidbody is attached to the object and gravity is enabled, something like this

    gameObj.rigidbody2D.AddForce(Vector3.up * 10 * Time.deltaTime); or 
    gameObj.rigidbody2D.AddForce(Vector3.up * 1000); 
    

    See which combination and what values matches your requirement and use accordingly. Hope it helps

提交回复
热议问题