Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Rotate Sprite and Move at Angle!  (Read 1956 times)

0 Members and 1 Guest are viewing this topic.

bryce910

  • Newbie
  • *
  • Posts: 31
    • View Profile
Rotate Sprite and Move at Angle!
« on: February 26, 2015, 07:24:17 am »
Hello everyone!

I am currently rotating a sprite by using:

sprite.rotate(1);

basically it is slowly rotating the sprite which works perfect. What I am not able to quite figure out is when I shoot a bullet from my sprite... for example which is located  at a 37* angle how would I go about getting the bullet to move in the same angle the sprite is rotated to? :-\

Thanks and hopefully I made that clear and understandable!
Bryce910

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Rotate Sprite and Move at Angle!
« Reply #1 on: February 26, 2015, 07:49:16 am »
Basic trigonometry:

x += cos(angle) * speed;
y += sin(angle) * speed;
Laurent Gomila - SFML developer

bryce910

  • Newbie
  • *
  • Posts: 31
    • View Profile
Re: Rotate Sprite and Move at Angle!
« Reply #2 on: February 26, 2015, 08:54:29 am »
Okay thank you! I never understood basic geometry! I will need to do some research it looks like! :P

StormWingDelta

  • Sr. Member
  • ****
  • Posts: 365
    • View Profile
Re: Rotate Sprite and Move at Angle!
« Reply #3 on: February 26, 2015, 04:53:02 pm »
Yep making games takes a lot of math.  I've met people who wanted to avoid using any kind of math in games before and found it rather funny.



In any event here's a few sites to get you started:

https://www.khanacademy.org/
http://www.gamedev.net/page/resources/_/technical/math-and-physics/practical-use-of-vector-math-in-games-r2968
http://en.wikibooks.org/wiki/Guide_to_Game_Development/Theory/Mathematics/Vectors

I have many ideas but need the help of others to find way to make use of them.