• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Lil_Lloyd

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

14 posts in this topic

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?
0

Share this post


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

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
1

Share this post


Link to post
Share on other sites
[quote name='Lil_Lloyd' timestamp='1342709739' post='4960954']
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
[/quote]

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

Share this post


Link to post
Share on other sites
[quote name='Lil_Lloyd' timestamp='1342709739' post='4960954']
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
[/quote]

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

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.
[/quote]

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

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

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

Share this post


Link to post
Share on other sites
[quote name='kunos' timestamp='1342711017' post='4960967']
[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.
[/quote]

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.

[quote name='SimonForsman' timestamp='1342710456' post='4960962']
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.
[/quote]

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.

[quote name='Mussi' timestamp='1342711456' post='4960969']
What do you expect to happen if they player keeps his left button pressed?
[/quote]

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

Share this post


Link to post
Share on other sites
[quote name='Lil_Lloyd' timestamp='1342739443' post='4961096']
The plane should turn to the 9 0clock position, and stay there.
[/quote]
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
0

Share this post


Link to post
Share on other sites
From the sounds of it what you want to do is rotate the player to an absolute screen position specified by the cursor key they pressed, regardless of their current orientation. So for example, While Left is held down, you rotate the player towards facing left (with respect to the screen). Similar for the other 3 directions. You shouldn't need to impose range restrictions for determining which direction to turn. You will however have to calculate which of anti-clockwise or clockwise rotation is shorter, and then do that.

So you'd have a key detection phase, where you set the target rotation, then a turning phase where you adjust the current rotation by a small offset in the direction of the target rotation.

That said I don't necessarily agree with this as a control system. I seems like it would be difficult to negotiate a curved track as you'd be dancing around 4 keys to achieve turns, rather than 2 with a more traditional rotate anti-clockwise or clockwise method.
0

Share this post


Link to post
Share on other sites
I think absolute controls are suited for action games, where you also use the mouse to shoot or something like that (e.g. Bloodline Champions, Babo Violent). I guess you could do the same with vehicles although as Postie said you need some extra logic to determine the best way to turn the vehicle in the desired direction. That does not only involve the steering of the wheels but also acceleration and breaking. So in total the player has less control over the vehicle that is why i probably would not do it that way if the focus is on racing.
0

Share this post


Link to post
Share on other sites
The most robust, fluid, and natural system is actually fairly trivial.


There is the direction you are actually facing, in screen coordinates, and the direction you want to face, in screen coordinates.
Every frame, rotate towards the preferred direction by a small amount. It is really just that simple.

Since my hard drive crash, I have not reinstalled Adobe Photoshop CS3 on this operating system, so I will explain with words.


Firstly imagine the player is facing south. The direction is [0, -1].
The player hits RIGHT. The preferred direction becomes [1, 0].


Frame starts.

First, find the shortest distance between the current angle and the preferred angle. If you spin the car clockwise you will have to go 270 degrees, whereas spinning counter clockwise means only 90 degrees.

You now know that you need to [b]add[/b] 90 degrees to get to the target. Adding means rotating counter clockwise, subtracting means clockwise.
[CODE]bool bNeg = false;
float fRot = 90; // You should be working with radians; this is for mental clarity.
[/CODE]

Second, perform a sanity check. Adding 90 degrees results in instant spinning to the desired direction. Then amount of rotation should be capped for a single frame.
[CODE]fRot = min( fRot, 5.0f ); // Adjust the amount to change the turning radius.[/CODE]

Third, add or subtract that amount to the current car rotation.
[CODE]cCar.AddRot( bNeg ? -fRot : fRot );[/CODE]

Repeat on next frame.

I kept fRot positive because it simplifies the min().


This handles all cases.
From any rotation, the car will smoothly rotate into the desired rotation as the player hits any combination of keys.
This also allows the player to hit any combination of keys, such as down-left, etc. And even if it is in the middle of a rotation it will just start from there and rotate into the new position smoothly.

The last detail is to not rotate the car if no keys are held.


L. Spiro Edited by L. Spiro
1

Share this post


Link to post
Share on other sites
Super awesome post! Thank you! [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0