Unity 2d跳跃脚本

用户名

有人在统一的2D游戏中有很好的跳跃脚本吗?我拥有的代码可以运行,但是距离跳转还很遥远,看起来像是在飞行。

using UnityEngine;
using System.Collections;

public class movingplayer : MonoBehaviour {

public Vector2 speed = new Vector2(10,10);

private Vector2 movement = new Vector2(1,1);

// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update () {
    float inputX = Input.GetAxis ("Horizontal");
    float inputY = Input.GetAxis ("Vertical");

    movement = new Vector2(
        speed.x * inputX,
        speed.y * inputY);

    if (Input.GetKeyDown ("space")){
                         transform.Translate(Vector3.up * 260 * Time.deltaTime, Space.World);
                 } 

}
void FixedUpdate()
{
    // 5 - Move the game object
    rigidbody2D.velocity = movement;
    //rigidbody2D.AddForce(movement);

}
}
周杰伦

通常跳跃的人使用Rigidbody2D.AddForceForcemode.Impulse似乎您的对象在Y轴上被推过一次,由于重力它会自动掉落。

例:

rigidbody2D.AddForce(new Vector2(0, 10), ForceMode2D.Impulse);

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章