Hi all!
So the problem is - i want my camera to fly around in the world, but it must look at the hero all the time. How can i attach camera target to hero, so it wouldn't be affected by camera animators?
Attached camera
Attached camera
Sincerely yours, Bazzilic
A scene node animator can easily handle that:
Use it like this:
Code: Select all
// In CCameraTargetAnimator.h
#ifndef CCAMERATARGETANIMATOR_H_INCLUDED
#define CCAMERATARGETANIMATOR_H_INCLUDED
#include <irrlicht.h>
namespace irr
{
namespace scene
{
class CCameraTargetAnimator : public ISceneNodeAnimator
{
public:
void animateNode( ISceneNode* node, u32 timeMs )
{
ICameraSceneNode* camera = (ICameraSceneNode*)node;
if ( Target != 0 )
{
camera->setTarget( Target->getAbsolutePosition() );
}
}
void setTarget( ISceneNode* target )
{
Target = target;
}
ISceneNode* getTarget() const
{
return Target;
}
CCameraTargetAnimator( ISceneNode* target )
{
Target = target;
}
private:
ISceneNode* Target;
};
}
}
#endif
Code: Select all
#include "CCameraTargetAnimator.h"
...
ISceneNode* hero = ...
ICameraSceneNode* camera = ...
CCameraTargetAnimator* anim = new CCameraTargetAnimator(hero);
camera->addAnimator(anim);
anim->drop();