3D Space Movement Left and Right

3D Space Movement Left and Right

Postby oldscruffy66 » 01 Apr 2015, 13:26

Hello I like playing with creating a game engine and recently loaded MD5 mesh with animation. The model and move about the world (terrain) forward, backward, rotate left and right. The camera only follows the character at this point. However I am stuck in the math for moving left and right. Not rotation left and right but a shuffle left and right.

For example:
Moving forward works fine.
radians = rotationY * 0.0174532925f;
positionX += sinf(radians) * forwardSpeed;
positionZ += cosf(radians) * forwardSpeed;

I've been through trig, calc, diffe, etc.. in university many many years ago so my math is needing a refresh. Any advice how to make a movement left and right in 3D Space?
oldscruffy66
 
Posts: 4
Joined: 13 Mar 2015, 19:27

Re: 3D Space Movement Left and Right

Postby eugeneloza » 01 Apr 2015, 13:36

I'm a little bit confused: You speak about 3D movement, but you give formulae for 2D movement (on a plane or at max 2.5D on a curved surface)...

If you're just speaking about 2D as example above then it's simple:

forward movement:
positionX += sinf(radians) * forwardSpeed;
positionZ += cosf(radians) * forwardSpeed;

Left strafe:
positionX += sinf(radians+Pi/2) * StrafeSpeed;
positionZ += cosf(radians+Pi/2) * StrafeSpeed;

Right strafe
positionX += sinf(radians-Pi/2) * StrafeSpeed;
positionZ += cosf(radians-Pi/2) * StrafeSpeed;

L&R might be swapped depending on XZ axis relation.
User avatar
eugeneloza
 
Posts: 500
Joined: 22 Aug 2014, 12:15
Location: Ukraine

Re: 3D Space Movement Left and Right

Postby oldscruffy66 » 01 Apr 2015, 15:44

thx Eugeneloz, works like a charm!

My bad, guess I am looking for 2D strafe movement. Height is based on terrain height.
oldscruffy66
 
Posts: 4
Joined: 13 Mar 2015, 19:27

Who is online

Users browsing this forum: No registered users and 1 guest