简体   繁体   English

解释设置Rigidbody2D速度的差异

[英]Explain the difference in setting a Rigidbody2D's velocity

So I am pretty new to Unity and I was trying to make a basic pong game. 所以我对Unity来说还很陌生,我试图制作一个基本的Pong游戏。 I'm using C# as my weapon of choice and was experimenting with different ways to assign a value to a Rigidbody2D's velocity. 我正在使用C#作为我选择的武器,并且正在尝试以不同的方式为Rigidbody2D的速度分配值。

   rb2D.velocity.Set(0f, speed);

and

   rb2D.velocity = new Vector2(0f, -speed);

My conundrum is that the top option doesn't apply the velocity at all, and the bottom one is the only way I can get it to work. 我的难题是,顶部选项根本不应用速度,而底部选项是我使速度起作用的唯一方法。 Can someone explain to me why the Set method doesn't apply the speed, and if so when would I actually use the Set method? 有人可以向我解释为什么Set方法不应用速度吗?如果是,我什么时候真正使用Set方法?

It's a dead field for c# as far I can remember. 据我所知,这对于C#来说是一个死领域。 Way back when they found out using set could lead to unrealistic behavior and in the documentation recommend you instantiate a new vector2 and apply it to your Rigidbody. 当他们发现使用set可能会导致不切实际的行为时,可以追溯到过去,在文档中建议您实例化一个新的vector2并将其应用于刚体。 Clunky but it's their approach. 笨拙,但这是他们的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM