Actionscript 3 这种冲动是从哪里来的?
我正在用AS3中的Box2D物理编写一个用a,D键(左键和右键)进行角色移动的代码,我不知道b2body是如何获得冲动的。在你将要看到的代码中,xActionscript 3 这种冲动是从哪里来的?,actionscript-3,flash,box2d,flashdevelop,Actionscript 3,Flash,Box2d,Flashdevelop,我正在用AS3中的Box2D物理编写一个用a,D键(左键和右键)进行角色移动的代码,我不知道b2body是如何获得冲动的。在你将要看到的代码中,x switch (moveState) { case "RIGHT": if (mainChar.GetLinearVelocity().x = 1.3) { impulse.x = 0.0; impulse.y = 0.0; mai
switch (moveState)
{
case "RIGHT":
if (mainChar.GetLinearVelocity().x = 1.3)
{
impulse.x = 0.0;
impulse.y = 0.0;
mainChar.ApplyImpulse(impulse, mainChar.GetPosition());
}
break;
case "LEFT":
if (mainChar.GetLinearVelocity().x = -1.3)
{
impulse.x = 0.0;
impulse.y = 0.0;
mainChar.ApplyImpulse(impulse, mainChar.GetPosition());
}
case "STOP":
if (mainChar.GetLinearVelocity().x > 0)
{
impulse.x = -mainChar.GetLinearVelocity().x;
impulse.y = 0.0;
mainChar.ApplyImpulse(impulse, mainChar.GetPosition());
impulse.x = 0.0;
}
if (mainChar.GetLinearVelocity().x < 0)
{
impulse.x = +mainChar.GetLinearVelocity().x;
impulse.y = 0.0;
mainChar.ApplyImpulse(impulse, mainChar.GetPosition());
impulse.x = 0.0;
}
if (mainChar.GetLinearVelocity().x = 0)
{
impulse.x = 0.0;
break;
}
开关(移动状态)
{
案例“权利”:
if(mainChar.GetLinearVelocity().x=1.3)
{
脉冲x=0.0;
脉冲y=0.0;
ApplyImpulse(pulse,mainChar.GetPosition());
}
打破
案例“左”:
if(mainChar.GetLinearVelocity().x=-1.3)
{
脉冲x=0.0;
脉冲y=0.0;
ApplyImpulse(pulse,mainChar.GetPosition());
}
案例“停止”:
if(mainChar.GetLinearVelocity().x>0)
{
pulse.x=-mainChar.GetLinearVelocity().x;
脉冲y=0.0;
ApplyImpulse(pulse,mainChar.GetPosition());
脉冲x=0.0;
}
if(mainChar.GetLinearVelocity().x<0)
{
pulse.x=+mainChar.GetLinearVelocity().x;
脉冲y=0.0;
ApplyImpulse(pulse,mainChar.GetPosition());
脉冲x=0.0;
}
if(mainChar.GetLinearVelocity().x=0)
{
脉冲x=0.0;
打破
}
在代码中,我没有给出Pulse.x值1.3或-1.3。关于if语句,有什么我不知道的吗?^”
编辑:哦,好吧,我猜“=”给它赋值。我不知道它-对我来说仍然有点奇怪,因为它在if条件中。(我的目的是测试相等性,“=”)
但是,我不想这样,是吗?我读到我不应该设置线性速度,而应该让b2body加速并保持在期望的速度。它来自这里:
if(mainChar.GetLinearVelocity().x=1.3)
。这是一个分配,而不是比较。冲动不是线性速度。这就是为什么会有ApplyImpulse
,而不仅仅是简单的Impulse=x
-如果你加上冲动,它会加快速度,如果你的世界计算分数,它会减慢速度。是的,我知道,我不是问D://我说我没有看到我给变量pulse.x赋值为1.3,这里:if(mainChar.GetLinearVelocity().x=1.3)
。如果需要比较,它应该是=
。现在将其赋值为1.3,并在if语句中执行操作。我会将其作为答案来写,但最好是因为输入错误而关闭问题。