使刚体2d向后退

时间:2018-12-08 17:48:08

标签: c# unity3d

我正在使用Unity来制作一个简单的Rtype风格的游戏。我对角色精灵的“刚体2d”物理学感到满意,但我希望能够向后移动!不确定如何用刚体物理学做到这一点?有没有一种方法可以使向下箭头将精灵向后加速?我的代码如下:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Fighter_movement : MonoBehaviour
{

    public float thrust;
    public float drag;
    public Rigidbody2D rb;

    // Use this for initialization
    void Start()
    {
        rb = GetComponent<Rigidbody2D>();
    }

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

        Vector2 movement = new Vector2(moveHorizontal, moveVertical);

        rb.AddForce(movement);

    }
}

0 个答案:

没有答案