Jittering polys (Cocos2Dx)

Official forum for the Chipmunk2D Physics Library.
Post Reply
Scratch
Posts: 2
Joined: Mon Jul 06, 2015 11:32 am
Contact:

Jittering polys (Cocos2Dx)

Post by Scratch »

I am creating a Cocos2Dx project where the idea is to stack shapes on screen as high as you can.
I used Physics Editor to define the fixtures, I've included the output for a regular pentagon:

Code: Select all

<key>blocks_ic_polygon</key>
			<dict>
				<key>anchorpoint</key>
                <string>{ 0.50000,0.50000 }</string>
                <key>fixtures</key>
                <array>

					<dict>
                        <key>mass</key>                         <real>2</real>
                        <key>elasticity</key>                  <real>0</real>
                        <key>friction</key>                     <real>2</real>
                        <key>surface_velocity</key>        <string>{ 0.00000,0.00000 }</string>
                        <key>layers</key>                       <integer>0</integer>
                        <key>group</key>                       <integer>0</integer>
                        <key>collision_type</key>           <integer>0</integer>
                        <key>isSensor</key>                    <false/>
                        <key>fixture_type</key>             <string>POLYGON</string>
                        
						<key>polygons</key>
						<array>
							<array>	
								<string>{ 74.00000,17.00000 }</string>	
								<string>{ 46.00000,-70.00000 }</string>	
								<string>{ -46.00000,-70.00000 }</string>	
								<string>{ -74.00000,17.00000 }</string>	
								<string>{ 0.00000,71.00000 }</string>
							</array>
						</array>
                        
					</dict>

				</array>
			</dict>
Kinda hard to read, sorry.
I am using PEShapeCache_X3_0 to parse the plist file and create the physics bodies.
The left, right and bottom of the screen are lined with non-dynamic physics bodies. Image

The problem is, is that once I get a few of the objects on screen they never come to rest. They have a rotational jitter that never seems to die down. I've set both the Update Rate and SubSteps up to (what I assume are) outrageous numbers to test stability with no joy. (0.1 and 256, respectively) The problem is diminished but not eliminated.

It also occasionally explodes. :(
Scratch
Posts: 2
Joined: Mon Jul 06, 2015 11:32 am
Contact:

Re: Jittering polys (Cocos2Dx)

Post by Scratch »

Declaring the PhysicsBodies manually makes no difference.
My tilmestep is pretty consistent at about 0.0015-0.0017.

Code: Select all

    auto sp = Sprite::create();
    auto sp_body = PhysicsBody::create();
    int shape = rand() % 3;
    if(shape == 0)
    {
        sp = Sprite::create("res/Shapes/blocks_ic_square.png");
        sp_body = PhysicsBody::createBox(Size(150, 150));
    }
    else if(shape == 1)
    {
        sp = Sprite::create("res/Shapes/blocks_ic_circle.png");
        sp->cocos2d::Node::setPosition(50, 50);

        sp_body = PhysicsBody::createCircle(100);
    }
    else{
        sp = Sprite::create("res/Shapes/blocks_ic_polygon.png");
        sp->cocos2d::Node::setPosition(50, 50);

        std::array<Point, 5> polyPoints = {Point(2,88),Point(76,142),Point(150,88),Point(122,1),Point(30,1)};
        sp_body = PhysicsBody::createPolygon(polyPoints.data(), 5);
    }
Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests