Jump to content
  • Advertisement
Sign in to follow this  
drwbns

Adding sprint ability - how?

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

How would I add a sprinting ability when Right Shift is held to the following code? Thanks for any help!

void InputController::injectKeyboardState(OIS::Keyboard* mKeyboard)
{
//camera
float walk = 0,strafe = 0, up = 0, sprint = 0;

if (mKeyboard->isKeyDown(OIS::KC_A))
{
strafe = -1;
}
else if (mKeyboard->isKeyDown(OIS::KC_D))
{
strafe = 1;
}
if (mKeyboard->isKeyDown(OIS::KC_W))
{
walk = -1;
}
else if (mKeyboard->isKeyDown(OIS::KC_S))
{
walk = 1;
}
if (mKeyboard->isKeyDown(OIS::KC_PGUP))
{
up = 1;
}
else if (mKeyboard->isKeyDown(OIS::KC_PGDOWN))
{
up = -1;
}

GST->GetCurrentCam()->UpdateLocation(walk, strafe, up);

//player
walk = 0, strafe = 0, sprint = 0;

if (mKeyboard->isKeyDown(OIS::KC_UP))
{
walk = 1;
}
else if (mKeyboard->isKeyDown(OIS::KC_DOWN))
{
walk = -1;
}
if (mKeyboard->isKeyDown(OIS::KC_LEFT))
{
strafe = 1;
}
else if (mKeyboard->isKeyDown(OIS::KC_RIGHT))
{
strafe = -1;
}

if (walk != 0 || strafe != 0)
{
Quaternion q = TPCAM->GetRotation().Inverse();
Ogre::Vector3 send(walk,0,strafe);
send = q * send;
PLAYER->orderMove(send.x,send.z);
}
}


I tried this - but it didn't do anything. :( help please.

void InputController::injectKeyboardState(OIS::Keyboard* mKeyboard)
{
//camera
float walk = 0,strafe = 0, up = 0, sprint = 0;

if (mKeyboard->isKeyDown(OIS::KC_A))
{
strafe = -1;
}
else if (mKeyboard->isKeyDown(OIS::KC_D))
{
strafe = 1;
}
if (mKeyboard->isKeyDown(OIS::KC_W))
{
walk = -1;
}
else if (mKeyboard->isKeyDown(OIS::KC_S))
{
walk = 1;
}
if (mKeyboard->isKeyDown(OIS::KC_PGUP))
{
up = 1;
}
else if (mKeyboard->isKeyDown(OIS::KC_PGDOWN))
{
up = -1;
}

GST->GetCurrentCam()->UpdateLocation(walk, strafe, up);

//player
walk = 0, strafe = 0, sprint = 0;

if (mKeyboard->isKeyDown(OIS::KC_UP))
{
if (mKeyboard->isKeyDown(OIS::KC_RSHIFT)) {
sprint = 1;
walk = sprint + 1;
}
else {walk = 1;}
}
else if (mKeyboard->isKeyDown(OIS::KC_DOWN))
{
if (mKeyboard->isKeyDown(OIS::KC_RSHIFT))
{
sprint = -1;
walk = sprint -1;
}
else {walk = -1;}
}
if (mKeyboard->isKeyDown(OIS::KC_LEFT))
{
if (mKeyboard->isKeyDown(OIS::KC_RSHIFT)) {
sprint = 1;
strafe = sprint + 1;
}
else { strafe = 1;}
}
else if (mKeyboard->isKeyDown(OIS::KC_RIGHT))
{
if (mKeyboard->isKeyDown(OIS::KC_RSHIFT)) {
sprint = -1;
strafe = sprint -1;
}
else { strafe = -1; }
}

if (walk != 0 || strafe != 0)
{
Quaternion q = TPCAM->GetRotation().Inverse();
Ogre::Vector3 send(walk,0,strafe);
send = q * send;
PLAYER->orderMove(send.x,send.z);
}
}

Share this post


Link to post
Share on other sites
Advertisement
[color="#1C2837"][font="CourierNew, monospace"][color="#666600"][color="#666600"]**** GAMEDEV PLZ FIX THE COPY PASTE THAT CREATES JUNK KTHXBAI ****[/font]
[font="CourierNew, monospace"] [/font][font="CourierNew, monospace"][color="#666600"]I had to edit that post 4 times...
[/font]
[color="#1C2837"][font="CourierNew, monospace"] [/font]
[color="#1C2837"][font="CourierNew, monospace"][color="#666600"][color="#666600"]I would do that:[/font]
[color="#1C2837"][font="CourierNew, monospace"]
float moveSpeed = 1;
if (mKeyboard->isKeyDown(OIS::KC_RSHIFT))
{[/font]
[color="#1C2837"][font="CourierNew, monospace"] moveSpeed = 2;[/font]
[color="#1C2837"][font="CourierNew, monospace"]}[/font]
[color="#1C2837"][font="CourierNew, monospace"]if (mKeyboard->isKeyDown(OIS::KC_A))[/font]
[color="#1C2837"][font="CourierNew, monospace"]{[/font]
[color="#1C2837"][font="CourierNew, monospace"] strafe = -moveSpeed;[/font][/font]
[color="#1C2837"][font="CourierNew, monospace"]}
[/font]
[color="#1C2837"][font="CourierNew, monospace"] [/font]
[color="#1C2837"][font="CourierNew, monospace"]Ok, I just can't get the code snippet to show up correctly :@[/font]
[font="CourierNew, monospace"][color="#1C2837"]Here is the non formated version:[/font]
[font="CourierNew, monospace"][color="#1C2837"]float moveSpeed = 1;[/font]
[font="CourierNew, monospace"][color="#1C2837"]if (Right shift down)[/font]
[font="CourierNew, monospace"][color="#1C2837"]{[/font]
[font="CourierNew, monospace"][color="#1C2837"] moveSpeed = 2; // What ever speed you want[/font]
[font="CourierNew, monospace"][color="#1C2837"]}[/font]
[font="CourierNew, monospace"][color="#1C2837"]if ('A' is down)[/font]
[font="CourierNew, monospace"][color="#1C2837"]{[/font]
[font="CourierNew, monospace"][color="#1C2837"] strafe = -moveSpeed;[/font]
[font="CourierNew, monospace"][color="#1C2837"]}[/font]
[font="CourierNew, monospace"][color="#1C2837"]...[/font]

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!