QuickBox2D poly behaviour vs box or circle

Posted by Ben Kanizay on Stack Overflow See other posts from Stack Overflow or by Ben Kanizay
Published on 2010-12-23T00:49:11Z Indexed on 2010/12/23 0:54 UTC
Read the original article Hit count: 260

Filed under:
|

Hi I've played a little with Box2D before and have just started using QuickBox2D which makes things heaps easier. I am however getting different behaviour with a specific poly shape than I am with a box. All other properties are the same. I've included 3 simple examples and their source below.

What I really want to work is Example 1 with both objects as poly. As you can see, it seems like the 'paddle' poly is the one that's failing - the 'ball' (whether it's a poly or circle) just falls straight through it instead of bouncing off as it does with a box 'paddle' object. Would appreciate some help or insight.

As I can only post one line at this stage, the swf previews of the 3 examples can be seen here

Example 1 source:

package {
import com.actionsnippet.qbox.QuickBox2D;
import com.actionsnippet.qbox.QuickObject;

import flash.display.MovieClip;

public class Eg1 extends MovieClip {

    private var sim:QuickBox2D;
    private var paddle:QuickObject;
    private var ball:QuickObject;

    public function Eg1() {
        this.sim = new QuickBox2D(this);
        this.paddle = this.sim.addPoly({
            x:13, 
            y:19, 
            angle:0, 
            density:0, 
            draggable:false, 
            isBullet:true, 
            verts:[[-3.84,-0.67,-2.84,-1,-2.17,-0.33,2.17,-0.33,2.84,-1,3.84,-0.67,2.84,1,-2.51,1]]
        });
        this.ball = this.sim.addPoly({
            x:13, 
            y:1, 
            restitution:1, 
            friction:1, 
            draggable:false, 
            isBullet:true, 
            verts:[[-0.34,-1,0.34,-1,0.67,-0.33,0.67,0.33,0.34,1,-0.34,1,-0.67,0.33,-0.67,-0.33]]
        });
        this.sim.start();
    }

}}

Example 2 source:

package {
import com.actionsnippet.qbox.QuickBox2D;
import com.actionsnippet.qbox.QuickObject;

import flash.display.MovieClip;

public class Eg2 extends MovieClip {

    private var sim:QuickBox2D;
    private var paddle:QuickObject;
    private var ball:QuickObject;

    public function Eg2() {
        this.sim = new QuickBox2D(this);
        this.paddle = this.sim.addBox({
            x:13, 
            y:19, 
            angle:0, 
            density:0, 
            draggable:false, 
            isBullet:true, 
            width:8
        });
        this.ball = this.sim.addPoly({
            x:13, 
            y:1, 
            restitution:1, 
            friction:1, 
            draggable:false, 
            isBullet:true, 
            verts:[[-0.34,-1,0.34,-1,0.67,-0.33,0.67,0.33,0.34,1,-0.34,1,-0.67,0.33,-0.67,-0.33]]
        });
        this.sim.start();
    }

}}

Example 3 source:

package {
import com.actionsnippet.qbox.QuickBox2D;
import com.actionsnippet.qbox.QuickObject;

import flash.display.MovieClip;

public class Eg3 extends MovieClip {

    private var sim:QuickBox2D;
    private var paddle:QuickObject;
    private var ball:QuickObject;

    public function Eg3() {
        this.sim = new QuickBox2D(this);
        this.paddle = this.sim.addPoly({
            x:13, 
            y:19, 
            angle:0, 
            density:0, 
            draggable:false, 
            isBullet:true, 
            verts:[[-3.84,-0.67,-2.84,-1,-2.17,-0.33,2.17,-0.33,2.84,-1,3.84,-0.67,2.84,1,-2.51,1]]
        });
        this.ball = this.sim.addCircle({
            x:13, 
            y:1, 
            restitution:1, 
            friction:1, 
            draggable:false, 
            isBullet:true, 
            radius:1
        });
        this.sim.start();
    }

}}

© Stack Overflow or respective owner

Related posts about actionscript-3

Related posts about box2d