c# - 让刚体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);
}
}
解决方案
推荐阅读
- visual-c++ - 在 Windows C++ 应用程序中获取显卡名称和信息的最佳方式是什么?
- privacy - 某些网站上的“使用 Facebook 注册”如何包含我的姓名甚至头像?
- python - 将数据集转换为要绘制的库列表
- python - 使用保存的模型进行 TensorFlow 推理
- java - 登录 Firebase 时出现什么问题
- python - Django - 对于帐户中子目录 /snippets 中的 html - TemplateDoesNotExist at /friend_request/user_id/
- c - 如何正确处理由c中的函数分配和交换的缓冲区
- symfony - 值“if”的意外令牌“名称”(预期“语句块结束”)
- sql - 想从原始表的结果中创建新表
- python-3.x - 如何通过 API 创建自定义字段?