Sign in to follow this  

What do you call straight forward motion?

This topic is 3461 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

So, in a WASD game, the W-S keys control back-and-forth movement, and A-D side-to-side. In my code, I call the latter strafe movement, so lots of variables gets prefixed with "strafe". For straight-forward movement, though, what do you call it? It's "longitudinal" right now, but for obvious reasons I don't want to keep typing that...

Share this post


Link to post
Share on other sites
In chess, movement parallel with the edges of the board is called 'cardinal'. The four points of a compass are the 'cardinal directions' or 'cardinal headings'. So try that.

On a partially unrelated note; why do you have variables prefixed with 'strafe'? What do they store?

Share this post


Link to post
Share on other sites
Quote:
Original post by Wyrframe
In chess, movement parallel with the edges of the board is called 'cardinal'. The four points of a compass are the 'cardinal directions' or 'cardinal headings'. So try that.

On a partially unrelated note; why do you have variables prefixed with 'strafe'? What do they store?


Mm, I like the sound of "cardinal," but wouldn't that refer to east and west as well as north and south? I'm thinking of just the movement analogous with north-south, relative to the mover.

As to why I have strafe variables: depending on WASD input, I calculate the speed the player wants to go in the longitudinal and strafe directions, and then set velocity accordingly.

Share this post


Link to post
Share on other sites
The word you're looking for is "Move"

W and S "Move" the player. Easy as that. It's a pretty common label for that functionality. A and D is pretty much exclusively refered to as "strafing" as you already call it.

Calling it anything else will confuse players. They'll get it if you call it "Moving" or "Move". Another popular term is "Forward/Backward" (or split it up individually).

Don't overcomplicate things.

Share this post


Link to post
Share on other sites
Why not just "forward" and "sideways"?

But really, chances are that the fact that you have two whole "sets" of variables - one set for motion in each access - points out a design problem. You should be defining some kind of 2-dimensional vector type instead, and using one set of variables with vector arithmetic.

Quote:
Original post by dashurc
Calling it anything else will confuse players.


He's looking for a convention for variable names. I doubt the players will see those, much less care about them.

Share this post


Link to post
Share on other sites
Quote:
Original post by Zahlman
Why not just "forward" and "sideways"?

But really, chances are that the fact that you have two whole "sets" of variables - one set for motion in each access - points out a design problem. You should be defining some kind of 2-dimensional vector type instead, and using one set of variables with vector arithmetic.


I've been shying away from "forwards," since the same axis is just as frequently negative. But, as you say, maybe I should reconsider the whole system, as people seemed surprised I'm making the distinction at all. Thanks for the advice.

Share this post


Link to post
Share on other sites
Quote:
Original post by Sol Blue
Quote:
Original post by Zahlman
Why not just "forward" and "sideways"?

But really, chances are that the fact that you have two whole "sets" of variables - one set for motion in each access - points out a design problem. You should be defining some kind of 2-dimensional vector type instead, and using one set of variables with vector arithmetic.


I've been shying away from "forwards," since the same axis is just as frequently negative. But, as you say, maybe I should reconsider the whole system, as people seemed surprised I'm making the distinction at all. Thanks for the advice.


Yeah, just let it all be considered a local movement vector. It's in player-space, meaning forward to the player is forward in the player's Z axis (or X or Y, depending on your coordinate system). So:

vector3 move(0, 0, 0);

// every frame or so
if (moveLeft) move.x += -1; // to the left
if (moveRight) move.x += 1; // to the right
if (moveForward) move.z += -1; // to the forward
if (moveBackward) move.z += 1; // to the backward

// global movement
vector3 movement = playerOrientation * move;
// now you'll want to clear the per-frame move variable
move = vector3(0, 0, 0);

Share this post


Link to post
Share on other sites
Thanks for the advice, agi_shi. I do something similar, actually. When it comes down to moving the object around, it has a velocity vector, which it scales by elapsed time and applies to its position vector. Before that, the longitudinal/strafe variables are used to track player input:

W: longitudinalSpeed += 300;
S: longitudinalSpeed -= 300;

A: strafeSpeed -= 300;
D: strafeSpeed += 300;

That sort of thing. These desired speeds are then used to build the velocity/position vectors when it's time to actually move.

There are probably ways I could track this without separate variables for the two axes, but what prompted the post was finding an alternative to the clunky "longitudinalSpeed."

Share this post


Link to post
Share on other sites
I just call my 4 potentially-analog axes Move, Strafe, Turn, and Look, because they're all short and reasonably descriptive. But actually maybe it would be better to combine move and strafe into a vector at the input system level. Especially since that would give a nice place to normalize the vector, to prevent the classic bug with independent x/z movement, where you go about 1.41 times as fast if you walk diagonally all the time :)

Share this post


Link to post
Share on other sites
You could use vectors as in agi_shi's example or you could simply use x and y variables if you want to keep your code as it is. Then, simply do a rotation transform on x and y based on the player's direction and add those to the current x and y values to get the new position. The vector example is more elegant but I'm _assuming_ this is closer to what you're trying to achieve.

Share this post


Link to post
Share on other sites
Quote:
Original post by agi_shi

vector3 move(0, 0, 0);

// every frame or so
if (moveLeft) move.x += -1; // to the left
if (moveRight) move.x += 1; // to the right
if (moveForward) move.z += -1; // to the forward
if (moveBackward) move.z += 1; // to the backward

// global movement
vector3 movement = playerOrientation * move;
// now you'll want to clear the per-frame move variable
move = vector3(0, 0, 0);


Maybe move should be called 'direction.'

Share this post


Link to post
Share on other sites
Quote:
Original post by Moomin
Quote:
Original post by agi_shi

vector3 move(0, 0, 0);

// every frame or so
if (moveLeft) move.x += -1; // to the left
if (moveRight) move.x += 1; // to the right
if (moveForward) move.z += -1; // to the forward
if (moveBackward) move.z += 1; // to the backward

// global movement
vector3 movement = playerOrientation * move;
// now you'll want to clear the per-frame move variable
move = vector3(0, 0, 0);


Maybe move should be called 'direction.'


Possibly. In my case it is never normalized, though, I treat it as the basis amount of movement for the current frame. Then it's scaled by the player speed and the delta time.

Share this post


Link to post
Share on other sites

This topic is 3461 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.

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