Hello everyone. I just started using irrlicht and need some help here...
i tried the tutorials in irrlicht and i managed to create a third person camera view on my model. it follows my character when it moves anywhere. But I've got a problem here. How to move the character move diagonally?
I'm using the class MyEventReceiver : public IEventReceiver provided by irrlicht in the examples.
I've made changes so that it accepts W A S D for movements.. however when i try to press more than 1 key at a time... for example W and A together to move diagonally left, it just takes on W or A depending on which one was pressed later...
how to I solve this problem?
I once thought of binding the FPS camera to the model while moving and use the camera's movements to control the character movement. but I ended up making the model fly sky high...
Oh I'm trying to make a game where the view is similar to Metal Gear Solid.. Where you can move your character in any direction and the camera doesn't really change view. like when you turn your character back, he just faces you...
Will appreciate it if i can get some help here
Controlling a character using keyboards only
Here is how to fix the problem...
Hi! I don't know Metal Gear Solid myself, but I think I can help you. You seem to have the right idea for controlling your character. I assume this is FPS game? I began making one, similar to Star Wars Battlefield in XBox. I decided that the FPS camera was the way to go, but of course my character would fly all over the place. I eventually posted a thread in the forum for fixing this and JP was able to solve my problem. It is really is quite simple. Obviously you make your camera the Parent to your model first. Then you have to make sure the Y target is disabled for the FPS camera. This is the same as disabling the user from looking up or down; the FPS can rotate but only look level. By doing this the FPS camera can't change height. Here is the code for doing this. Note the use of Vector3df. You could just use simple ints but this would require more coding and would be not as well integrated with Irrlicht. Also be aware of the constant "height" which I have set to 500. Change this to anything you want:
Just add this in the device->run() loop and this will correct the problem. Be aware that on some really, really slow computers this might make your app run a bit slowly and jiggly. For your info, you might have seen people suggest the "noVerticalMovement" flag for the FPS camera. This stops the camera from changing height, but the 3rd person view can be directed up and down. You character would then continue to fly all around! This is not what you want!:lol:
I hope this has helped,
3ddev
Code: Select all
vector3df current_camera_target;
current_camera_position = camera->getTarget();
vector3df correct_camera_postion;
correct_camera_postion.Y = 500;
camera->setTarget(correct_camera_postion);
I hope this has helped,
3ddev
ermmmm thanks for the help
but the game i'm making is not really a FPS...
its a third person game.... just that player movement is not determined by mouse... rather the camera just follows the character wherever he goes...
camera never changes view. it just changes position.
its like setting the camera->settarget(MYMODEL)
and then setting teh camera to be some distance away from teh model .
then if the player moves left, the camera still looks at it and shift its position left by the same amount too. and also the same for forawrd back and right...
I think i'm not explaining very well. haha sorry about it.
but the game i'm making is not really a FPS...
its a third person game.... just that player movement is not determined by mouse... rather the camera just follows the character wherever he goes...
camera never changes view. it just changes position.
its like setting the camera->settarget(MYMODEL)
and then setting teh camera to be some distance away from teh model .
then if the player moves left, the camera still looks at it and shift its position left by the same amount too. and also the same for forawrd back and right...
I think i'm not explaining very well. haha sorry about it.
actually my issue wasn't the camera. i know how to settle the camera problem. its my character control via keyboard... haha
i couldn't press 2 keys at the same time to move the character...
but me and my friend has somehow found a method to over come it alreayd. thanks all anyway!!!
i think its my fault for not being clear in the first place
i couldn't press 2 keys at the same time to move the character...
but me and my friend has somehow found a method to over come it alreayd. thanks all anyway!!!
i think its my fault for not being clear in the first place
Make your own key state class, which allows you to check key presses. You can apply my event-classes. They may help you: FILE
And the usage:
And the usage:
Code: Select all
input::EventHandler eventHandle;
IrrlichtDevice* device = createDevice(video::EDT_OPENGL, core::dimension2d<s32>(640, 480),
16, false, false, false, &eventHandle);
eventHandle.initMouseSupport(device);
input::MouseHandler Mouse(&eventHandle, device);
ipunt::KeyBoardHandler Keys(&eventHandle);
// ... other code....
// main loop:
while(!Keys.Hit(KEY_ESCAPE))
{
// beginScene-function
if(Keys.Down(KEY_KEY_A) && Keys.Down(KEY_KEY_B))
{
// do something...
}
Mouse.Update();
Keys.Update();
// endScene-function
}
Dattebayo!!