Player movement and changing rotation depending on the way they are facing

Started by
13 comments, last by Lil_Lloyd 11 years, 9 months ago
Kind of a long title, I apologise! Ok, What I want to know is an efficient simple way to handle player movement after they have turned 180 degrees. For example, let's say I'm programming an overhead racer or flying a jet fighter through canyons from an overhead perspective.

When the player is facing north, left banks left, obviously! This is achieved through some counter clockwise rotation. Right banks right, obviously! This is achieved through some clockwise rotation.

HOWEVER lets say the player character/vehicle is now facing south. The player will press right to turn right on the screen, but relative to the player character this is still in fact their left! They turn left on screen and the player starts crying.

So....how do we implement this kind of system so that player movement in a racer is congruent to a player's expectations?
Advertisement
i would not change anything. The player presses right to kind of rotate the vehicle clockwise. That is what I would expect, and that is also how it works in all games with this kind of gameplay.

edit: e.g. micro machines comes to mind
Micro machines was fun, but I remember it taking a while to get used to. If I see something moving in a downwards direction and I press left I expect it to turn left, and if I want to create some exciting and crazy turns for tracks I'd rather have more intuitive controls.

I thought of a way to do this anyway now:

a switch statement using the avatar's current facing direction:

going counter clockwise from the 3 o'clock or 0 degrees position:

if angle > 0 && angle <= 180:
left rotates left, right rotates right

if angle > 90 && angle <= 270:
up rotates right down rotates left

if angle > 180 && angle <= 360:
left rotates right and right rotates left

if angle > 270 && angle <= 360 && angle <= 90:
down rotates right and up rotates left

if angle > 0 && angle <= 180:
left rotates left, right rotates right

if angle > 90 && angle <= 270:
up rotates right down rotates left

if angle > 180 && angle <= 360:
left rotates right and right rotates left

if angle > 270 && angle <= 360 && angle <= 90:
down rotates right and up rotates left


Or you can use radians, several game engines use radians instead of degrees, that way there's consistency in the math language throughout the whole code.

Micro machines was fun, but I remember it taking a while to get used to. If I see something moving in a downwards direction and I press left I expect it to turn left, and if I want to create some exciting and crazy turns for tracks I'd rather have more intuitive controls.

I thought of a way to do this anyway now:

a switch statement using the avatar's current facing direction:

going counter clockwise from the 3 o'clock or 0 degrees position:

if angle > 0 && angle <= 180:
left rotates left, right rotates right

if angle > 90 && angle <= 270:
up rotates right down rotates left

if angle > 180 && angle <= 360:
left rotates right and right rotates left

if angle > 270 && angle <= 360 && angle <= 90:
down rotates right and up rotates left


Such a system would become quite annoying or inconsistent in long turns,

The player will expect to be able to do a 360 degree turn by holding either left or right, if you swap the controls around at various angles it will get really wierd.
[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!

HOWEVER lets say the player character/vehicle is now facing south. The player will press right to turn right on the screen, but relative to the player character this is still in fact their left! They turn left on screen and the player starts crying.


No I think they would cry if that didn't happen.
It is the correct behaviour, you are turning left or right with reference to the character, not to the screen.

Stefano Casillo
TWITTER: [twitter]KunosStefano[/twitter]
AssettoCorsa - netKar PRO - Kunos Simulazioni

What do you expect to happen if they player keeps his left button pressed?

You could also rotate the camera with the vehicle, that way left is always left and right is always right.
I guess there is two ways of doing top down controls. EIther relativ to the player or absolute. I do not think a mixed approach would be a good idea.

[quote name='Lil_Lloyd' timestamp='1342660466' post='4960748']
HOWEVER lets say the player character/vehicle is now facing south. The player will press right to turn right on the screen, but relative to the player character this is still in fact their left! They turn left on screen and the player starts crying.


No I think they would cry if that didn't happen.
It is the correct behaviour, you are turning left or right with reference to the character, not to the screen.
[/quote]

It isn't REALLY though is it? See: PAC MAN. As I'm making a quick to pick up flying simulation around a maze like track this is the system I'm going for, but as an option I can always leave in the so-called "correct" scheme, just so everyone is happy! Thanks for the input.


The player will expect to be able to do a 360 degree turn by holding either left or right, if you swap the controls around at various angles it will get really wierd.


I see what you mean, however in my game design there isn't any need for such turns, as the 'tracks' are basically canyons and are quite tight, no room or need to do a 180, but thanks for the input.


What do you expect to happen if they player keeps his left button pressed?


The plane should turn to the 9 0clock position, and stay there.

The plane should turn to the 9 0clock position, and stay there.

In that case, I don't think the example code you've posted will suffice(it'll wobble left and right). You'll have to store what state the player is currently in, the first time the button is pressed and use that to decide how rotation follows.

This topic is closed to new replies.

Advertisement