Jump to content

View more

Image of the Day

Boxes as reward for our ranking mode. ヾ(☆▽☆)
#indiedev #gamedev #gameart #screenshotsaturday https://t.co/ALF1InmM7K
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

SDL mouse

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
2 replies to this topic

#1 Slider_SLO   Members   

136
Like
0Likes
Like

Posted 12 November 2012 - 03:50 AM

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.
Tnx guys

#2 kd7tck   Members   

735
Like
0Likes
Like

Posted 12 November 2012 - 05:03 PM

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.

http://www.policyalmanac.org/games/aStarTutorial.htm:this will explain pathfinding

I recomend python/pygame over c/c++/SDL for begginers.

#3 incertia   Members   

787
Like
0Likes
Like

Posted 14 November 2012 - 06:53 PM

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

what




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.