Okay so I need to make a warp function which basically takes the player to the position of the mouse. The problem is I am using Box2d so my sprite is pasted to the position of the physics box. now I have tried a number of different things and have really boiled it down to one problem.
Here's the code before I go into it:
void Character::Update()
{
////This is where I update the position for Box2d physics box. and then I paste the sprite to that position//////
Position = playerBody->GetPosition();
Position.x *= b2PixelRatio;
Position.y *= b2PixelRatio;
dbSprite(iD,Position.x,Position.y,2);
dbPasteSprite(iD,Position.x,Position.y);
/////////Move the character/////////
if ( checkLeft() )
{
playerBody->ApplyImpulse(b2Vec2(-5,0),b2Vec2(Position.x,Position.y));
}
if ( checkRight() )
{
playerBody->ApplyImpulse(b2Vec2(5,0),b2Vec2(Position.x,Position.y));
}
if ( checkUp() )
{
playerBody->ApplyImpulse(b2Vec2(0,-10),b2Vec2(Position.x,Position.y));
}
if (LeftMouseClicked())
{
Primary();
}
}
/////////this is my warp function. I am getting the value of the mouse and setting it to a float. I then take the position of the box2d and set it equal to the mouse position./////////////
void Character::Primary()
{
PlayerPositionX = dbMouseX();
PlayerPositionY = dbMouseY();
Position.x = PlayerPositionX;
Position.y = PlayerPositionY;
}
Now when I watch the values Position.x after I hit the left click they are all equal to the mouse position.
So I looked into this function:
playerBody->GetPosition()
and in the GetPosition() (which is a box2d function) it looks like this
inline const b2Vec2& b2Body::GetPosition() const
{
return m_xf.position;
}
So basically m_xf is the value that I need to change because when I watch the value of it, it never changes. So how do I change the value in the box2d function? Or am I just thinking about this in the wrong way?
Sorry for the long post. It was the only way I could explain my problem.