Tell me more ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

In 2d, in degrees, negative degrees possible.

What I want is to rotate the player to face the same direction as the door before opening it, but when I'll do the same again now from the opposite side, the player will face backwards now.

I use Python.

share|improve this question
1  
This isn't a place where you ask us to write your code for you. Try it yourself, then ask us if you have any specific questions about how to do tht. – Jonathan Hobbs Aug 24 '12 at 9:58
What's with the negative responses? I have tried it already, I wouldn't waste my time posting here and waiting for an answer if I could just try it. Obvious for you is not obvious for me. – user975135 Aug 24 '12 at 10:06
The negative responses are because what you wrote is less a question of "how do I approach this?" and more a request of: "Here's what I want to do, now do it for me" - we answer questions here, we're not a code-writing service (though answering programming questions can involve writing code). Given that it's not that, though, I can point you in the right direction. – Jonathan Hobbs Aug 24 '12 at 10:16
What, because I said I use Python? People do post codes here as answers, FYI, and if someone used a C-style pseudocode it might be difficult for me to understand. – user975135 Aug 24 '12 at 10:21
No, because you just told us what you want, and assigned us the task of writing what you wanted, in the spirit of us doing your work, not in the spirit of us assisting your work. – Jonathan Hobbs Aug 24 '12 at 11:25

1 Answer

Look into vectors (an excellent tutorial is provided in the information attached to the vector tag) and interpolation.

The following will make sense if you read that linear algebra tutorial:

If you have a vector for the door position and the player position, you can calculate the direction you need the player to face in order to have them face the door. You can then simply make the player face this direction.

If you also have a unit vector representing the player's direction, you can also interpolate between the player's current direction, and the direction they'll need in order to face the door, in order to create as mooth turn.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.