Box2D Forums

It is currently Fri May 24, 2013 9:41 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Fri Mar 02, 2012 6:04 am 
Offline

Joined: Fri Mar 02, 2012 5:22 am
Posts: 2
Hi

I've got a weird little Problem that I have not been able to figure out.

What I want to to and why:
I need an Arrow that is constantly rotating around a character. When the player presses a button, the character is supposed to throw a bomb in the direction of the arrow. However, he should not do so if the Bomb would immediately hit a wall and kill him with its explosion.

To detect whether or not a wall is in the way of the planned bomb path, I wanted to use a sensor. It is fixed to the character and rotates around him, using a RevoluteJoint to connect it and setAngularVelocity() to get it moving. This works. But the Sensor, even if it has no shapes attached to it at all, seems to affect the character.
Since it has no mass, I figured it would just rotate around the character and not cause any feedback, but this does not seem to be the case. The character / sensor combination tumbles a little, just like it would if I attached a solid body with weight and had it rotate. The effect is very small, but from time to time it is even visible in the graphical representation, so I can not ignore it.

This is the Code I am using right now:

Code:
// define the Sensor
BodyDef sensorDef = new BodyDef();
sensorDef.type = BodyType.DYNAMIC;
sensorDef.position.set((float) (x), (float) (y + radius * 2));
sensorDef.angularDamping = 0f;
sensorDef.userData = this;
sensor = world.createBody(sensorDef);

// connect and get moving
RevoluteJointDef jointDef = new RevoluteJointDef();
jointDef.initialize(characterBody, sensor, characterBody.getWorldCenter());
world.createJoint(jointDef);
sensor.setAngularVelocity(2);


Am I missing something here or should I do this another way entirely?


Top
 Profile  
 
PostPosted: Fri Mar 02, 2012 8:54 am 
Offline

Joined: Fri Mar 02, 2012 5:22 am
Posts: 2
I think I found the problem.

The origin (sensorDef.position) of the character was not the same as the origin of the sensor. Now that they are both the same, it works.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: psbot [Picsearch] and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group