Hi, I am using C++ and trying to make my player shoot projectiles. I have done OK so far, but the problem is that what I have done to move them is just use:
bulletX += xOffset( betwen player and mouse ) /100
bulletY += yOffset / 100
This gave me the right direction although there was an issue, the closer the mouse was to the player, the slower the bullet went ( as you can probably tell from the code above ). I have tried:
Dlen = sqrt(Dx*Dx + Dy*Dy)
Dx/=Dlen;
Dy/=Dlen
Bx=Bx+Dx*Bs;
By=By+Dy*Bs;
*Dlen = normalised value, Dx = xOffset, Dy = yOffset, Bx= bulletX, By= bulletY, Bs = bullet Speed.
but I was unsuccesful.... the bullet went in completely random directions very different to where I was aiming.
I also tried to find a ratio :
yOffset / xOffset and then always move X by 1 or -1 and y by 1 or -1 multiplied by the ratio.
Again unscuccesful.
Is there any way to achieve a constant speed when shooting projectiles from a player in the direction of the mouse cursor that will work? Please put an explained example.