Hi all im kinda new with SDL and im making game for my self as a practise run really,
Iwe been having couple of problems i want it to be top down shooter...
Now i have no idea how to make my character follow and turn where the mouse is and bullet animition fire in direction of the mouse.
If i could get any tips from you guys i would be really glad i just dont know where to start with this one.
Bullet animation would use line of sight, meaning as long as there is a straight line between origin and dest and no objects between them the bullet will move in a straight line. For character following the mouse you will need pathfinding, this way the character can navigate from pointA to pointB avoiding all obstacles.
Well, given that you know the location of two points (i.e. the character and the cursor), you can figure out the angle that you need to rotate the character to make him look at the cursor.
Suppose your cursor is currently at and your character sprite is located at the point .
Then the vector from the character pointing towards the cursor is . This is the direction your character needs to walk in and it has length . If you want to scale it down to a unit vector so his walk speed is only impacted by direction and not distance, just divide by so your ideal direction vector is just