Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为什么不是';我的子弹不是用rb.velocity移动的吗?_C#_Unity3d_Scripting_Bullet - Fatal编程技术网

C# 为什么不是';我的子弹不是用rb.velocity移动的吗?

C# 为什么不是';我的子弹不是用rb.velocity移动的吗?,c#,unity3d,scripting,bullet,C#,Unity3d,Scripting,Bullet,我想自己制作一个小型的太空射击游戏,但在制作子弹预制件时遇到了一个问题。我在“开始”方法中设置它的速度,当我按“播放”时,它根本不移动 public float speed; Rigidbody2D rb; void Start() { rb = GetComponent<Rigidbody2D>(); rb.velocity = transform.forward * speed; } 公共浮动速度; 刚体2d rb; void Start() { rb=Get

我想自己制作一个小型的太空射击游戏,但在制作子弹预制件时遇到了一个问题。我在“开始”方法中设置它的速度,当我按“播放”时,它根本不移动

public float speed;
Rigidbody2D rb;

void Start()
{
    rb = GetComponent<Rigidbody2D>();
    rb.velocity = transform.forward * speed;
}
公共浮动速度;
刚体2d rb;
void Start()
{
rb=GetComponent();
rb.velocity=变换向前*速度;
}

我在我的玩家脚本中也使用了rb.velocity来移动他,效果很好。

它不起作用,因为你把rb.velocity=transform.forward*speed;进入启动功能

试试这个脚本

public float speed;
Rigidbody2D rb;

void Start()
{
    rb = GetComponent<Rigidbody2D>();

}

void Update()
{
    rb.velocity = transform.forward * speed;
}
公共浮动速度;
刚体2d rb;
void Start()
{
rb=GetComponent();
}
无效更新()
{
rb.velocity=变换向前*速度;
}

两个问题:1)两个对象的“速度”是否正确初始化?2) 两个物体的刚体上是否有相同的“is Kinetic”值?两个物体的速度都在inspector中初始化。什么是刚体动力学?我知道普通刚体有运动学,但我在2d oneMmm中没有看到,很好的一点:我不确定界面中是否有,但您也可以通过代码设置:。顺便说一句,这只是一个建议,不能确定它是否有帮助……是的,我不知怎么做了,我只是放弃了使用速度和附加力的想法。