C# 向二维刚体添加速度

C# 向二维刚体添加速度,c#,unity3d,2d,C#,Unity3d,2d,我刚刚开始使用Unity,我决定制作一个2D小行星克隆,到目前为止,我的旋转和运动都在下降,但我似乎不知道如何让飞船保持速度(所以你继续移动,直到你在相反方向上施加相等的力)。。。这就是我目前所拥有的 using UnityEngine; using System.Collections; public class movement : MonoBehaviour { void Update () { GameObject facer = GameObject.Find("facer

我刚刚开始使用Unity,我决定制作一个2D小行星克隆,到目前为止,我的旋转和运动都在下降,但我似乎不知道如何让飞船保持速度(所以你继续移动,直到你在相反方向上施加相等的力)。。。这就是我目前所拥有的

using UnityEngine;
using System.Collections;

public class movement : MonoBehaviour {

void Update () {
    GameObject facer = GameObject.Find("facer");
    //Facer is another object I am using as a sort of aiming reticle

    if(Input.GetKey(KeyCode.UpArrow))
    {
        this.transform.position = Vector3.MoveTowards(this.transform.position, facer.transform.position, 0.1f);
    }
    if(Input.GetKey(KeyCode.DownArrow))
    {
        this.transform.position = Vector3.MoveTowards(this.transform.position, facer.transform.position, -0.1f);
    }
    if(Input.GetKey(KeyCode.LeftArrow))
    {
        RotateLeft();
    }
    if(Input.GetKey(KeyCode.RightArrow))
    {
        RotateRight();
    }
}
void RotateLeft() {
    transform.Rotate (Vector3.back * -5f);
}
void RotateRight() {
    transform.Rotate (Vector3.forward * -5f);
}

}这就是你的问题吗

[yourigidbody].velocity=transform.forward*速度


[yourigidbody].velocity=transform.TransformDirection(向量3([xspeed]、[yspeed]、[zspeed])

这就是你的问题吗

[yourigidbody].velocity=transform.forward*速度


[yourigidbody].velocity=transform.TransformDirection(向量3([xspeed]、[yspeed]、[zspeed])

这就是你的问题吗

[yourigidbody].velocity=transform.forward*速度


[yourigidbody].velocity=transform.TransformDirection(向量3([xspeed]、[yspeed]、[zspeed])

这就是你的问题吗

[yourigidbody].velocity=transform.forward*速度

[yourigidbody].velocity=transform.TransformDirection(向量3([xspeed]、[yspeed]、[zspeed])