Page 1 of 1

Rotating toward a clicked point

Posted: Sat Nov 14, 2009 6:08 am
by MarvLeonidasX
How do you rotate a vector to face a clicked point. Like in many RPG's when you click on a spot on the ground and your character changes his/her facing toward to clicked spot as he/she moves towards it?

I hope I am making sense.

Posted: Sat Nov 14, 2009 7:00 am
by netpipe
use the force!

Posted: Sat Nov 14, 2009 7:03 am
by Serg88
I see 2 ways

use virtual ISceneNode * getSceneNodeFromRayBB (const core::line3d< f32 > &ray, s32 idBitMask=0, bool bNoDebugObjects=false, ISceneNode *root=0)=0

PlayerNode->getPosition().rotationToDirection(TargetNode);

2ways is using
getSceneNodeFromScreenCoordinatesBB
then
getCollisionResultPosition

for example only

Code: Select all

	scene::ISceneManager* smgr = this->device->getSceneManager();
	scene::ISceneCollisionManager * scm = smgr->getSceneCollisionManager();
	core::line3df = scm->getRayFromScreenCoordinates( this->device->getCursorControl()->getPosition() );
	core::vector3df target = scm->getCollisionResultPosition(selector, ...);
//then rotate yours model
PlayerNode->getPosition().rotationToDirection(TargetNode);
it`s complicated, but fewer errors
both function-describe you can find here:

http://irrlicht.sourceforge.net/docu/cl ... nager.html