Rotation and Movement question

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
timofiend
Posts: 14
Joined: Tue Feb 22, 2011 5:57 pm
Location: 115

Rotation and Movement question

Post by timofiend »

Hi, I am trying to make my character move in the direction he is facing, using slightly adapted code from the movement tutorial on the website. But I dont understand how I make the character change the direction he is walking, relative to where is facing.

The code I am using from the tutorial for movement is this

Code: Select all

			    core::vector3df nodeRotation = node1->getRotation();

                if(receiver.IsKeyDown(irr::KEY_KEY_A))
                        nodeRotation.Y += MOVEMENT_SPEED * frameDeltaTime;
                else if(receiver.IsKeyDown(irr::KEY_KEY_D))
                        nodeRotation.Y -= MOVEMENT_SPEED * frameDeltaTime;

				node1->setRotation( core::vector3df(nodeRotation) ); 


                core::vector3df nodePosition = node1->getPosition();
	

                if(receiver.IsKeyDown(irr::KEY_KEY_W))
                        nodePosition.Z -= MOVEMENT_SPEED * frameDeltaTime;
                else if(receiver.IsKeyDown(irr::KEY_KEY_S))
                        nodePosition.Z += MOVEMENT_SPEED * frameDeltaTime;

                node1->setPosition(nodePosition);
Only edited slightly so when A or D is pressed the character rotates instead of strafes left/right.

Could anyone give me an idea as to how I would change the direction he is walking to be the direction he is facing when being rotated? I have done abit of searching on the forums and I gather I would possibly need to use a rotation matrix? But I am quite new to this and dont really understand.

Any help would be appreciated, thanks.
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Re: Rotation and Movement question

Post by serengeor »

Have you ever seen the mighty Search button? This has been answered billions of times by now.
Working on game: Marrbles (Currently stopped).
timofiend
Posts: 14
Joined: Tue Feb 22, 2011 5:57 pm
Location: 115

Post by timofiend »

It appears my searching skills are terrible lol. I searched twice before I posted this, and couldnt find anything. Then I just searched again and found something instantly.
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Post by serengeor »

timofiend wrote:It appears my searching skills are terrible lol. I searched twice before I posted this, and couldnt find anything. Then I just searched again and found something instantly.
There ya go :wink:
Working on game: Marrbles (Currently stopped).
Post Reply