Jump to content
  • Advertisement
Sign in to follow this  
Infinite_Daremo

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.

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

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
	float cosPitch = (float)cos(DEG2RAD(m_pitch));
	float sinYaw = (float)sin(DEG2RAD(m_yaw));
	float negSinPitch = (float)sin(DEG2RAD(-m_pitch));

	// 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(cos(DEG2RAD(m_yaw + 90.0)))*strafeSpeed;
	m_position.z += float(sin(DEG2RAD(m_yaw + 90.0)))*strafeSpeed;
	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 this post


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


Link to post
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.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!