Page 1 of 1

Stupid question about control model

Posted: Wed Dec 28, 2005 9:05 am
by byelan74
I want model walk by pressed W, A, S, D key. i can animate model, but i cant make it move by pressed a key. i have walkthrough all of tutorial and i serch in the forum, but i still have a problem.

i'm not good in English. Sorry..... :oops:

Help me Please... :?:

Posted: Wed Dec 28, 2005 11:24 am
by AndreOdendaal
You'll need an IEventReceiver to capture the keyboard input.

Cast your object as IAnimatedMeshSceneNode and use AnimationSpeed to make the model walk. (IE set the speed to 0 by default and when the user presses a key set the AnimationSpeed to whatever it needs to be.).

Lastly you can use SetFrameLoop to manage what of the mesh is rendered.

Then you just need to update the position and rotation of the object depending on the speed you want the model to walk and its rotation

Posted: Wed Dec 28, 2005 3:04 pm
by byelan74
Please code for me please...... :oops:

Posted: Wed Dec 28, 2005 3:09 pm
by boboS

Posted: Wed Dec 28, 2005 5:20 pm
by byelan74
I can set a key but i cant code in that case.
i have no idea to make it walk. :roll:
switch(event.KeyInput.Key)
{
case KEY_KEY_W:
{
****** I dont know, how to code in this ******
}

Posted: Thu Dec 29, 2005 1:21 am
by XFactor
case KEY_KEY_W:
{
vector3df moveForward = yourNodeName->getAbsolutePosition();
moveForward.Y += 50; // Work with this part to find the correct direction
yourNodeName->setPosition(moveForward);
}

Posted: Sat Dec 31, 2005 10:55 am
by byelan74
Thanks XFactor. that code is worked. but it not smooth.

are there any way to make it smooth.

thanks everybody.

Posted: Sat Dec 31, 2005 11:03 am
by razmott
Hi !

I think you should use an Animator like this:

case KEY_KEY_W:
{
vector3df moveForward = yourNodeName->getAbsolutePosition();
moveForward.Y += 50;
ISceneNodeAnimator* runto = SceneManager->createFlyStraightAnimator(
yourNodeName->getAbsolutePosition(), moveForward, time, 0);
yourNodeName->addAnimator(runto);
runto->drop();
}

PS : "time" is a constant which will define your model speed.

Posted: Sat Dec 31, 2005 11:05 am
by boboS
Look at the wiki page and search for bool keys[].

If you use array of booleans to tell if a key is pressed, movement should be smother.