Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.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
Actionscript 3 这种冲动是从哪里来的?_Actionscript 3_Flash_Box2d_Flashdevelop - Fatal编程技术网

Actionscript 3 这种冲动是从哪里来的?

Actionscript 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

我正在用AS3中的Box2D物理编写一个用a,D键(左键和右键)进行角色移动的代码,我不知道b2body是如何获得冲动的。在你将要看到的代码中,x

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语句中执行操作。我会将其作为答案来写,但最好是因为输入错误而关闭问题。