andenginegame-physicsrevolute-joints

Andengine - RevoluteJointDef torque


I am following this amazing tutorial (http://www.matim-dev.com/revolute-joint.html) to create a RevoluteJointDef, just like the blog describes. Everything worked as it is explained, BUT I am getting an undesirable behavior.

Problem: When my body(1x1 meter) ball fall over(colide) the rotating body, it slow down for a while, even if I set its torque to a very high value.

What I want: When my body colide with this rotating body, it should behave just like it was hitting the ground. The rotating body should not slow down.

Here is my code:

Rectangle rotatingRectangle = new Rectangle(x_+120, y_, 240, 10,vbom);
                        rotatingRectangle.setColor(Color.RED);
                        final Body rotatingRectangleBody = PhysicsFactory.createBoxBody(simulationPhysicsWorld, rotatingRectangle, BodyType.DynamicBody, PhysicsFactory.createFixtureDef(1, 0.5f, 1f));
                        simulationPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(rotatingRectangle, rotatingRectangleBody, true, true));
                        GameScene.this.attachChild(rotatingRectangle);



                        revoluteJointDef = new RevoluteJointDef();
                        revoluteJointDef.initialize(staticRectBody, rotatingRectangleBody, staticRectBody.getWorldCenter());
                        revoluteJointDef.enableMotor = true;
                        revoluteJointDef.motorSpeed = (float)Math.toRadians(-60);
                        revoluteJointDef.maxMotorTorque = 1000000000;

The object that colides with this rotating body is a Sprite:

FixtureDef PLAYER_FIX= PhysicsFactory.createFixtureDef(10.0f, 0.5f, 0.1f);  
simulationSpriteProjectile= new Sprite(900,camera.getHeight()/2, resourcesManager.simulationTextureRegionProjectile, vbom);
simulationBodyProjectile  = PhysicsFactory.createCircleBody(simulationPhysicsWorld, simulationSpriteProjectile, BodyType.DynamicBody, PLAYER_FIX);

How can I achieve that?


Solution

  • I think this page has the example code what you need from andengine examples. https://github.com/nicolasgramlich/AndEngineExamples/blob/GLES2/src/org/andengine/examples/PhysicsRevoluteJointExample.java

    This should help!