试图做出 Seek and Flee 行为。无法将类型 'void' 隐式转换为 'Microsoft.Xna.Framework.Vector2'
Trying to make a Seek and Flee behavior. Cannot implicitly convert type 'void' to 'Microsoft.Xna.Framework.Vector2'
我正在尝试为 AI 项目制作 Seek and Flee 行为。我尝试输入算法,但出现此错误。我不明白为什么它不起作用,我可以使用一些指导。
这是无法正常工作的代码段:
public Vector2 Seek(Vector2 source, Vector2 target, float maxAccel)
{
Vector2 acceleration = (target - source).Normalize() * maxAccel;
return acceleration;
}
Normalize()
函数的documentation for the Normalize()
function says it returns a void, but you're trying to assign it to a variable of type Vector2
. You'll probably want to use this variant如下:
Vector2 acceleration = Vector2.Normalize(target - source) * maxAccel;
我假设 target
和 source
都是 Vector2
类型并且 maxAccel
是标量值。
我正在尝试为 AI 项目制作 Seek and Flee 行为。我尝试输入算法,但出现此错误。我不明白为什么它不起作用,我可以使用一些指导。
这是无法正常工作的代码段:
public Vector2 Seek(Vector2 source, Vector2 target, float maxAccel)
{
Vector2 acceleration = (target - source).Normalize() * maxAccel;
return acceleration;
}
Normalize()
函数的documentation for the Normalize()
function says it returns a void, but you're trying to assign it to a variable of type Vector2
. You'll probably want to use this variant如下:
Vector2 acceleration = Vector2.Normalize(target - source) * maxAccel;
我假设 target
和 source
都是 Vector2
类型并且 maxAccel
是标量值。