Well, right now I'm making a project in irrlicht and there's a movement problem
the movement keys are:
W - go forward
S - go back
A - strafe left
D - strafe right
Q - rotate left
E - rotate right
Spacebar - jump
everything's right except for two things, the jumping code and the direction of the character's movement
at first if I press W the character is going forward without any problem but when I move it after rotating it (let's just say I rotate it to the right) it's strafing left and not moving forward.
so what I want to know is how do I move the character according to where it's facing
secondly the jump code,when I press spacebar the screen becomes jaggy (or jagged,hm?) maybe because the jumping code is fighting against the gravity and collision detection code,so how do I jump right?
thanks in advance to anyone who helps,and this is my code if you wanna know:
in the MyEventReceiver class:
Code: Select all
if(event.EventType == EET_KEY_INPUT_EVENT)
{
if(event.KeyInput.Key == KEY_KEY_W)
{
up = event.KeyInput.PressedDown;
}
if(event.KeyInput.Key == KEY_KEY_S)
{
down = event.KeyInput.PressedDown;
}
if(event.KeyInput.Key == KEY_KEY_A)
{
left = event.KeyInput.PressedDown;
}
if(event.KeyInput.Key == KEY_KEY_D)
{
right = event.KeyInput.PressedDown;
}
if(event.KeyInput.Key == KEY_KEY_Q)
{
rotateleft = event.KeyInput.PressedDown;
}
if(event.KeyInput.Key == KEY_KEY_E)
{
rotateright = event.KeyInput.PressedDown;
}
if(event.EventType == EET_KEY_INPUT_EVENT && event.KeyInput.PressedDown && event.KeyInput.Key == KEY_SPACE)
{
jump = true;
}
else
{
jump = false;
}
}
Code: Select all
core::vector3df c = AlanNode->getPosition();
core::vector3df d = AlanNode->getRotation();
if(up)
{
c.Z -= KecepatanGerak;
}
if(down)
{
c.Z += KecepatanGerak;
}
if(left)
{
//d.Y -= 0.1f;
c.X += KecepatanGerak;
}
if(right)
{
//d.Y += 0.1f;
c.X -= KecepatanGerak;
}
if(rotateleft)
{
d.Y -= 2.0f;
}
if(rotateright)
{
d.Y += 2.0f;
}
if(jump)
{
c.Y += 10.0f;
}
AlanNode->setRotation(d);
AlanNode->setPosition(c);
camera->setTarget(c);