So I have a component set up that will fire bullets forward from an enemy in a 2d scrolling shooter.
What I need to have is the bullets firing towards the player position in a line.
I have tried looking up various posts about this but everything I try doesn't work for some reason.
Can anyone help point out what I'm doing wrong. I have the initial position of the bullet when fired. And the player position. I'm finding the difference by subtracting bullet position from player position. But I am unsure how to use this in setPosition()?
Here is what I have:
void BulletPhysicsComponent::update(double dt)
{
Vector2f bPos = _parent->getPosition();
auto pl = _parent->scene->ents.find("player");
Vector2f pPos = pl[0]->getPosition();
Vector2f diff = pPos - bPos;
_parent->setPosition(diff * (float)dt);
_parent->setRotation((180 / b2_pi) * _body->GetAngle());
}