Hold shift to make the FPS camera go faster
Hold shift to make the FPS camera go faster
Hi,
My question is quite simple: How do I make it so when I hold down shift, the movement speed of an FPS camera is increased?
Cheers.
My question is quite simple: How do I make it so when I hold down shift, the movement speed of an FPS camera is increased?
Cheers.
Last edited by Lorian on Wed Nov 07, 2007 4:27 pm, edited 1 time in total.
Yes, you're right, sorry about that!
You could have two cameras. One setup with the running speed and one setup with the walking speed and then when you press shift you switch the the running one (smgr->setActiveCamera(runningCam);) and then when you let go of shift you change it back to the walking cam.
You could have two cameras. One setup with the running speed and one setup with the walking speed and then when you press shift you switch the the running one (smgr->setActiveCamera(runningCam);) and then when you let go of shift you change it back to the walking cam.
Yeah that's another possible solution, you could move it progressively just by saying if the shift button is held down add on a chunk of 'speed' each frame (based on the elapsed time so you get a smooth increase whatever the framerate) until it reached the max speed for running and if shift isn't held down you reduce the speed similarly until it gets to the walking speed.
You'd obviously already have some code to move the dummy scene node, that the camera is attached to, around smoothly based on a speed parameter.
You'd obviously already have some code to move the dummy scene node, that the camera is attached to, around smoothly based on a speed parameter.
Thanks for the help.
I'm not bothered about a gradual increase in speed, it's not supposed to be representing a human running anyway.
I tried usig two cameras, here's the event receiver code:
The camera jumps around when I press shift, sometimes moving quite a large distance from where it was. Any idea?
I'm not bothered about a gradual increase in speed, it's not supposed to be representing a human running anyway.
I tried usig two cameras, here's the event receiver code:
Code: Select all
if (event.EventType == irr::EET_KEY_INPUT_EVENT &&
event.KeyInput.PressedDown) {
// Fast camera when shift is held down
if (event.KeyInput.Key == irr::KEY_LSHIFT ||
event.KeyInput.Key == irr::KEY_RSHIFT) {
graphics->fastCamera->setPosition(graphics->normalCamera->getPosition());
graphics->fastCamera->setRotation(graphics->normalCamera->getRotation());
graphics->smgr->setActiveCamera(graphics->fastCamera);
}
} else if (event.EventType == irr::EET_KEY_INPUT_EVENT &&
!event.KeyInput.PressedDown) {
// Normal camera speed when shift is up
if (event.KeyInput.Key == irr::KEY_LSHIFT ||
event.KeyInput.Key == irr::KEY_RSHIFT) {
graphics->normalCamera->setPosition(graphics->fastCamera->getPosition());
graphics->normalCamera->setRotation(graphics->fastCamera->getRotation());
graphics->smgr->setActiveCamera(graphics->normalCamera);
}
I guess because when you move the normalCamera the fastCamera stays where it was last time before you changed the camera from fast to normal so when you set the fast camera back on, it jumps from the place it was last used to where the normal camera is (before the switch).
To fix it maybe change the position of the fast camera even when it isn't used so when you switch between them it will start from the place the normal camera was last used.
I'm bit tired so forgive me for being maybe unclear about things I said..
To fix it maybe change the position of the fast camera even when it isn't used so when you switch between them it will start from the place the normal camera was last used.
I'm bit tired so forgive me for being maybe unclear about things I said..
right, and don't forget updateAbsolutePosition on the camera after this...MasterGod wrote:To fix it maybe change the position of the fast camera even when it isn't used so when you switch between them it will start from the place the normal camera was last used.
But (in my opinion) the best way is to add a setSpeed function to the camera scene node !!!
like I did with my IrrExtensions...
while(!asleep) sheep++;
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
the updateAbsolutePosition is often needed after setting position/rotation of a camera to prevent it from stuttering...
Yes, my IrrExtensions are only for Windoofs, sorry...
But this depends only for the program itself, the extensions are for Irrlicht and so they can be used on any OS...
contact me via email, maybe I can help you for this single extension...
Yes, my IrrExtensions are only for Windoofs, sorry...
But this depends only for the program itself, the extensions are for Irrlicht and so they can be used on any OS...
contact me via email, maybe I can help you for this single extension...
while(!asleep) sheep++;
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
-
- Posts: 1638
- Joined: Mon Apr 30, 2007 3:24 am
- Location: Montreal, CANADA
- Contact:
One thing you could do is: (The way I'm thinking for doing my FPS with run and walk)
- Define 2 cameras a running fps camera and a walking fps Camera
- If you are in walking mode and press shift:
Copy the values (position, rotation,etc) of the walking camera to the running one and switch the active camera to the running one.
- If you release the shift:
Copy the values (position, rotation, etc) of the running camera to the walking one and switch the active camera to the walking one.
The only problem you will have that way is that you will not be able to have a progressive acceleration. It still could be possible to do a progressive acceleration, but will mean, creating on the fly a new camera with a new speed switch to it, then create another one with the new speed (time based), switch to it. etc. until you have reach the desired speed. That is not very efficient at all.
The best thing would have to control all of the aspect of the FPS camera controller, but the methods are not available at the moment. (So we could only change the camera speed based on time, and you would have your acceleration)
EDIT: Lorian, you code is nice. That would do it. But you could perhaps add a "state" variable to know if the camera is running or walking. (like a boolean). I think that could be the problem with the "jump". Because it's could switch from the fast camera to the slow camera about anytime.
- Define 2 cameras a running fps camera and a walking fps Camera
- If you are in walking mode and press shift:
Copy the values (position, rotation,etc) of the walking camera to the running one and switch the active camera to the running one.
- If you release the shift:
Copy the values (position, rotation, etc) of the running camera to the walking one and switch the active camera to the walking one.
The only problem you will have that way is that you will not be able to have a progressive acceleration. It still could be possible to do a progressive acceleration, but will mean, creating on the fly a new camera with a new speed switch to it, then create another one with the new speed (time based), switch to it. etc. until you have reach the desired speed. That is not very efficient at all.
The best thing would have to control all of the aspect of the FPS camera controller, but the methods are not available at the moment. (So we could only change the camera speed based on time, and you would have your acceleration)
EDIT: Lorian, you code is nice. That would do it. But you could perhaps add a "state" variable to know if the camera is running or walking. (like a boolean). I think that could be the problem with the "jump". Because it's could switch from the fast camera to the slow camera about anytime.