Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.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 尝试在Citrus引擎中使用Box2D生成挥剑攻击_Actionscript 3_Flash_Box2d_Citrus Engine_Box2d Joints - Fatal编程技术网

Actionscript 3 尝试在Citrus引擎中使用Box2D生成挥剑攻击

Actionscript 3 尝试在Citrus引擎中使用Box2D生成挥剑攻击,actionscript-3,flash,box2d,citrus-engine,box2d-joints,Actionscript 3,Flash,Box2d,Citrus Engine,Box2d Joints,在过去的几天里,我一直在想如何正确地扩展CitrusEngine的Box2DPhysicsObjects来生成我的自定义对象。我的目标是产生这种行为: 这是为了模拟我的英雄在挥舞剑攻击时,在使用输入确定的方向上冲刺。剑“休眠”直到攻击状态被激活 我想我对如何正确使用Box2D(尤其是接头)有一个基本的误解。如果有人能给我指出正确的方向,我将永远感激。我无法真正提供我当前的代码,因为它已经无法使用了。像上面这样的实现会有非常差的性能,并且可能在几乎所有情况下都会使用隧道。因此,解决方案是添加一个

在过去的几天里,我一直在想如何正确地扩展CitrusEngine的Box2DPhysicsObjects来生成我的自定义对象。我的目标是产生这种行为:

这是为了模拟我的英雄在挥舞剑攻击时,在使用输入确定的方向上冲刺。剑“休眠”直到攻击状态被激活


我想我对如何正确使用Box2D(尤其是接头)有一个基本的误解。如果有人能给我指出正确的方向,我将永远感激。我无法真正提供我当前的代码,因为它已经无法使用了。

像上面这样的实现会有非常差的性能,并且可能在几乎所有情况下都会使用隧道。因此,解决方案是添加一个漏斗形状的传感器,并在该传感器和我的英雄之间添加一个接头。实施:

    override protected function createShape():void{

        var radius:Number = 4;
        var vertices:Vector.<b2Vec2> = new Vector.<b2Vec2>();
        vertices.push(new b2Vec2(0,0));

        for (var i:int = 0; i < 7; i++) {
            var angle:Number = i / 6.0 * .5* Math.PI;
            vertices.push(
                new b2Vec2( radius * Math.cos(angle), 
                            radius * Math.sin(angle) ));
        }

        var sword_shape:b2PolygonShape = new b2PolygonShape();
        sword_shape.SetAsVector(vertices,8);
        _shape = sword_shape;       
    }
重写受保护的函数createShape():void{
变量半径:数值=4;
变量顶点:向量。=新向量。();
push(新的b2Vec2(0,0));
对于(变量i:int=0;i<7;i++){
变量角度:数值=i/6.0*.5*Math.PI;
推(
新b2Vec2(半径*数学坐标(角度),
半径*数学sin(角度));
}
var shape:b2PolygonShape=新的b2PolygonShape();
剑形。SetAsVector(顶点,8);
_形状=剑形;
}