How to find out the player's orientation (N,S,E,W)?
Because "player check rotation" returns very high numbers beyond 360º (even negative ones) instead of returning to 0º.
A free tool for creating oldschool FPS games · By
OK you can approximate the sine and cosine functions but it's very difficult i've tried and it's just kind of messy.
One way you could figure this out is if you use the modulus operation (mod
) to ensure that the rotation value stays within a certain range. For example, let's say your rotation value can go above 360 degrees or below -360 degrees. By taking the rotation and modding it by 360, you essentially wrap the value around within the range of 0 to 360 degrees.
Here's a simple Python example: ```python def get_direction(rotation): # Ensure rotation is within 0 to 360 degrees rotation %= 360 # Determine direction based on ranges if rotation >= 315 or rotation < 45: return "North" elif rotation >= 45 and rotation < 135: return "East" elif rotation >= 135 and rotation < 225: return "South" else: return "West" # Example usage player_rotation = 420 # Example rotation direction = get_direction(player_rotation) print("Player is facing:", direction) ```
Some things may not be accurate'cause I'm not checking this in E F P S E. I think that facing forward is 90 degrees in the engine so you'd have to change this code appropriately.
There are other various game methods but I don't know them and the other ones I do all involve trigonometry functions which are not built in :)