I'm fairly new to box2d, so any help would be appreciated. I'm using the iPhone port (along with the cocos2d library). What I'm looking to achieve is for my player characters box2d body to rotate towards the location of the last touched point.
Here's the code I'm currently working with (where pBody is the player Body and location is a CGPoint containing the x and y location of the last known player touch):
While the code compiles, I'm getting errant rotation. Any advice would be greatly appreciated!
Here's the code I'm currently working with (where pBody is the player Body and location is a CGPoint containing the x and y location of the last known player touch):
Code:
CGPoint location = [touch locationInView: [touch view]];
location = [[CCDirector sharedDirector] convertToGL: location];
//CCSprite *actor = (CCSprite*)pBody->GetUserData();
b2Vec2 pos = pBody->GetPosition();
float xpos = pos.x * PTM_RATIO;
float ypos = pos.y * PTM_RATIO;
pBody->SetTransform(pos, atan2f(location.y - ypos, location.x - xpos));
location = [[CCDirector sharedDirector] convertToGL: location];
//CCSprite *actor = (CCSprite*)pBody->GetUserData();
b2Vec2 pos = pBody->GetPosition();
float xpos = pos.x * PTM_RATIO;
float ypos = pos.y * PTM_RATIO;
pBody->SetTransform(pos, atan2f(location.y - ypos, location.x - xpos));
While the code compiles, I'm getting errant rotation. Any advice would be greatly appreciated!