I have got a little Problem with moving objects.
What I tried to do was turn the object by ->setrotation() and then move it to this direction.
I've read some tutorials about it and I know that I have to use sin/cos functions for it...but I did not understand how to do that.
I've tried some codes I've found here in the forum, but they did not work :-/
Code: Select all
if(receiver.IsKeyDown(irr::KEY_UP))
{
Charpos = character->getPosition();
charrotate = character->getRotation();
Charpos.X = Charpos.X + ( MOVEMENT_SPEED * cos(charrotate.Y*pi/180));
Charpos.Z = Charpos.Z - ( MOVEMENT_SPEED * sin(charrotate.Y*pi/180));
character->setPosition(Charpos);
}
I am using the Eventreceiver from the Moving Tutorial.
Can anyone see the mistake in this?
BB
EDIT:Now I understand this sin/cos functions, but they doesn't work any better...I have got improved my code a little bit (I think):
Code: Select all
if(receiver.IsKeyDown(irr::KEY_UP))
{
pos.Z += cos(rot.Y)*speed;
pos.X += sin(rot.Y)*speed;
character->setPosition(pos);
}