Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Player's Orientation

A topic by Monkey_Luke created May 06, 2024 Views: 145 Replies: 2
Viewing posts 1 to 3

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º.

I have thought about the sin and cos functions.
If the sin of "direction" is greater than 0 the orientation is north, if the sin of "direction" is less than 0 the orientation is south.
But I can't use the sin and cos functions in EFE.
Any idea?

(1 edit)

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 :)