【发布时间】:2022-01-02 04:08:46
【问题描述】:
大家好,基本上我想知道如何将这个运动脚本更改为使用刚体。它按照我想要的方式工作,wasd 改变外观方向,然后空间从那个方向向前移动,但我想将它全部转换为使用刚体完成,这样我就可以进行碰撞。谢谢!!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Fly : MonoBehaviour
{
public float moveSpeed;
void Start()
{
}
void Update()
{
if (Input.GetKey(KeyCode.Space))
{
transform.Translate(new Vector3(0,0,moveSpeed) * Time.deltaTime, Space.Self);
}
float rotatex = Input.GetAxis("Vertical");
float rotatey = Input.GetAxis("Horizontal");
transform.Rotate(0, rotatey, 0, Space.World);
transform.Rotate(-rotatex * 0.5f, 0, 0);
}
}
【问题讨论】:
-
您可能想要添加 RigidBody 并使用 FixedUpdate 调用 RigidBody.MovePosition 和 RigidBody.MoveRotation。
-
请使用正确的标签!请注意,
unityscript是或更好的是曾经是一种 JavaScript 风格,类似于早期 Unity 版本中使用的自定义语言,并且现在已经不推荐使用了!您的代码显然在c#...
标签: c# unity3d game-development