# Orientation aligned strafing (Resolved )

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

## Recommended Posts

Im trying to get an entity to move through its current orientation and with some half assed code i mananged to get generally working with this (this was originally code for an FPS camera:
// calculate trig functions

// speed is velocity z-component
float speed = m_velocity.z * deltaTime;

// strafe speed is velocity x-component
float strafeSpeed = m_velocity.x * deltaTime;

// speed limit
//if (speed > 15.0)
//	speed = 15.0;
//if (strafeSpeed > 15.0)
//	strafeSpeed = 15.0;
//if (speed < -15.0)
//	speed = -15.0;
//if (strafeSpeed < -15.0)
//	strafeSpeed = -15.0;

// friction
//if (m_velocity.Length() > 0.0)
//	m_acceleration = -m_velocity * 1.5f;

//m_velocity += m_acceleration * deltaTime;

// calculate new position of entity
m_position.x += float(cosPitch)*speed;
m_position.z += float(negSinPitch)*speed;


Problem is when i attempt to strafe by adding velocity to its Z component it still strafes on the worlds Z (or X but you know what i mean) axis. To do that i use the following:
void moveRight() { m_velocity += CVector( m_movementSpeed, 0, 0);}


What can i tweak to get strafing working? A link to or some code would be greatly appreciated. Thanks. [Edited by - Infinite_Daremo on July 23, 2008 2:25:47 PM]

##### Share on other sites
You shouldn't use pitch. For moving forward / backward and strafe left / right use yaw only. Like this:
	m_position.x += float(cos(DEG2RAD(m_yaw)))*speed;	m_position.z += float(sin(DEG2RAD(m_yaw)))*speed;	m_position.x += float(cos(DEG2RAD(m_yaw + 90.0)))*strafeSpeed;	m_position.z += float(sin(DEG2RAD(m_yaw + 90.0)))*strafeSpeed;

##### Share on other sites
Using the code you provided restricts the model to only moving in strict angles ( i.e. north, east, south, west ) I needed pitch so the model would move in the direction it was facing.

EDIT: Got it working. Just a little tweak to the code you provided worked. Thanks so much.

1. 1
Rutin
49
2. 2
3. 3
4. 4
5. 5

• 10
• 28
• 20
• 9
• 20
• ### Forum Statistics

• Total Topics
633410
• Total Posts
3011727
• ### Who's Online (See full list)

There are no registered users currently online

×