SFML community forums
Help => Graphics => Topic started by: iHope on March 15, 2012, 01:39:52 pm
-
Hi, I'm currently trying to make a top-down shooter. I have done kinda a lot of stuff into it, but now I'm stuck at very annoying little problem. I need to make mouse rotation, again I have no idea how to do this. The idea is that the player would look at the cursor. I could rotate the player using cursor so you could use WASD to move around.
-
What's your problem exactly?
This is quite simple to do:
sf::Vector2i cursor = sf::Mouse::getPosition(window);
sf::Vector2f worldCursor = window.convertCoords(cursor.x, cursor.y);
sf::Vector2f direction = worldCursor - player.getPosition();
player.setRotation(std::atan2(direction.y, direction.x));
(SFML 2)
-
Okay, thank you. I'm not really good at maths(I'm in junior high school).
-
Vector algebra is essential for serious game programming, I'm sure there are good pages on the internet to learn it. You could also start with Wikipedia ;)
-
Yeah, thats true. I'm just too lazy to do so, because if vector algebra is going to be learned in school, I won't try to learn it now. <- English would be a lot more practical :D
-
Argh, I didn't look that code sample too well. The window isn't moving so the window is still, no moving around(Isn't sf::view used for that?). Then I'm using SFML 1.6(Too retard to install without proper install guide). And by the way, do I the code sample when mouse is moved?
if(sf::Event::MouseMoved)
{ //Do the code sample }
-
It seems like you're too lazy in general :P
- Concerning the vector algebra, it's your decision, but you definitely need it in game programming. If you learn it now, you'll have less problems in school ;)
- Both installing SFML 1.6 and SFML 2.0 is explained very well in the tutorials, we can't speak about "no proper install guide".
- The code you showed is wrong. Also this is explained in the tutorials, but you have to actually read them.
- Generally, you should know that as a programmer, you often have to search informations on your own (concerning documentation, programming language, specific techniques, ...). No one will teach you them, so you must learn them by yourself.
I don't want to offend you, consider those points as good advice :)
-
You're true about my laziness and I know I shouldn't be so lazy. And I know all those advices are true. Personally I hate installing different libraries, I think it's more harder than programming actually. BUT I'm gonna grow myself a spine and install SFML 2.
EDIT: Got SFML2 working :)