vector3df pos - position of character
vector3df target - position of camera
Code: Select all
float ratio= abs((target.X- pos.X)/ (target.Z- pos.Z));
float x= 1/ tan(ratio);
node->setRotation(vector3df(0, x, 0));
Code: Select all
float ratio= abs((target.X- pos.X)/ (target.Z- pos.Z));
float x= 1/ tan(ratio);
node->setRotation(vector3df(0, x, 0));
Code: Select all
#include <cmath>
vector2df character( characterposition.X, characterposition.Z );
vector2df camera( camerapos.X, camerapos.Z );
vector2df diff = camera - character;
//Get the angle in radians and convert to degrees
f32 angle
= atan2( diff.X, diff.Y ) * 180/3.14;