Topic: How to add an object Behavior in C ++?

I have tried many ways to add Behavior LookAt a camera but no way it works, how it is done?

Re: How to add an object Behavior in C ++?

Hi, start with this tutorial :
http://www.maratis3d.org/?p=500

Re: How to add an object Behavior in C ++?

If you just want to add a behavior to an object in c++.

You can use the behavior manager if you don't have access to the behavior code directly:

MEngine *engine = MEngine::getInstance();
MBehaviorManager * bManager = engine->getBehaviorManager();

MBehaviorCreator * bCreator = bManager->getBehaviorByName("LookAt");

MBehavior *behavior = bCreator->getNewBehavior(object);
object->addBehavior(behavior);

MVariable var0 = behavior->getVariable(0); // var 0 is "target"
MString *targetName = (MString *)var0.getPointer();
*targetName = "objetNameToLookAt";

If you have access to the behavior class you can do this directly:

MBLookAt *behavior = MBLookAt::getNew(object);
object->addBehavior(behavior);