unity3d - 尝试在统一 2d 中移动对象
问题描述
物体没有沿着斜坡向下移动
如何在 2d 中统一移动对象这是我的代码:
public class move : MonoBehaviour
{
public float moveSpeed = 3f;
Rigidbody2D rig;
float yat ;
void Start()
{
rig = GetComponent<Rigidbody2D>();
}
void Update()
{
float xat = Input.GetAxis("Horizontal");
yat = rig.velocity.y;
rig.velocity = new Vector2(xat*moveSpeed,yat);
}
}
解决方案
我很抱歉,我不明白你想做什么?但是,如果您只是移动对象,您可以尝试“Transfrom.Translate”方法。
顺便说一句,使用速度方法在您自己的版本中尝试此代码:
float speed = 0.5f;
...
void Update () {
float inputHorizontal = Input.GetAxisRaw("Horizontal");
player.velocity = Vector2.right * inputHorizontal * speed;
}
Imo 这应该可以,如果您有任何其他疑问,请告诉我。
推荐阅读
- git - 为什么我的 git diff 在@@ 之后显示评论
- python - 在 django 中为用户创建公共配置文件
- python - 反向波兰符号算法不能与相同的操作数正确工作
- html - WKWebView 画布问题。画布内的链接没有做任何事情
- ruby-on-rails - 如何修复 RVM gemsets 中的 [missing bin/ruby] 列表
- python - 如何从 Win-R 窗口更改目录?
- php - PHP、Angular、HTACCESS - 只允许来自源域的请求
- swift - NavigationBarTitle 自动显示模式不起作用
- c++ - 无法使用 ESP32 连接到家庭 WiFi?
- c# - 命名动态生成的组合框项