Jump to content
  • Advertisement
Sign in to follow this  
Lil_Lloyd

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

This topic is 2161 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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 Edited by Inferiarum

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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. Edited by Mussi

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!