首页 > 解决方案 > 让刚体2d向后退

问题描述

我正在使用 Unity 制作一个简单的 Rtype 风格的游戏。我对我的角色精灵的rigidbody2d 物理感到满意,除了我希望能够向后移动!不确定如何使用刚体物理来做到这一点?有没有办法让向下箭头向后加速精灵?我的代码如下:

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);

    }
}

标签: c#unity3d

解决方案


推荐阅读