Page 1 of 1

[AI class] problem with rotation

Posted: Sun Sep 04, 2005 4:04 pm
by Guest
i've got some model. I made a very simple AI class for it.

Code: Select all

(...)	  
direction = enemy->getPosition() - me->getPosition();     
direction.normalize();
(...)
vector3d<f32> zwrot() {
   return direction;
}
(...)
this is the code from my class, where "enemy" is ICameraSceneNode* and "me" is IAnimatedMeshSceneNode*.
And in my main aplication I've got something like this:

Code: Select all

bot->setRotation(bot_ai.zwrot());
there are no errors, but it doesn't work. How to make bot look at me ??

Posted: Sun Sep 04, 2005 6:59 pm
by CZestmyr
You can't do it this way.
If the vector3df is used for rotation, it has the data stored in radians (i gues), but your function returns just the distance from you to the enemy.

I suggest you do this:

Code: Select all

vector3df vec = me->getPosition() - enemy->getPosition();
vec.getHorizontalAngle();

//This then converts degrees to radians
vec *= GRAD_PI2;

bot->setRotation(vec);
That should do...

Posted: Mon Sep 05, 2005 2:34 pm
by lor
I forgot to log in. Sorry. Ok,vec.getHorizontalAngle(); doesn't work..


check it out :

'class irr::core::vector3df' has no member named 'GetHorizontalAngle'
:roll:
so how to do it if this doesn't work ??

Posted: Mon Sep 05, 2005 2:34 pm
by lor
I forgot to log in. Sorry. Ok, doesn't work..
vec.getHorizontalAngle();

check it out :

'class irr::core::vector3df' has no member named 'GetHorizontalAngle'
:roll:
so how to do it if this doesn't work ??

Posted: Mon Sep 05, 2005 2:36 pm
by lor
I forgot to log in. Sorry. Ok,vec.getHorizontalAngle(); doesn't work..


check it out :

'class irr::core::vector3df' has no member named 'GetHorizontalAngle'
:roll:
so how to do it if this doesn't work ??

Posted: Mon Sep 05, 2005 5:27 pm
by CZestmyr
It must work. At least it causes no problem on my compoter :P

Tips:

1. Do I really see 'GetHorizontalAngle' with uppercase G? Do you know, that C++ is case-sensitive? Th function name is getHorizontalAngle()
2. What version of irrlicht are you using? Use the highest version number, if possible. I myself have 0.10.0 and am considering downloadin 0.12.0.
3. I'm out of ideas...

Posted: Tue Sep 06, 2005 6:09 pm
by lor
and are you sure, you used vector3df ?? I use the same version, and I tried using G for g

Posted: Tue Sep 06, 2005 8:04 pm
by evo
The getHorizontalAngle fuction returns a vector. So you can use something like this:

Code: Select all

core::vector3df   Direction(1.0f, 1.0f, 1.0f);
core::vector3df   Rotation;
Rotation = Direction.getHorizontalAngle();
printf("Rotation xyz=%3.3f,%3.3f,%3.3f\n", Rotation.X, Rotation.Y, Rotation.Z);

Posted: Tue Sep 06, 2005 9:29 pm
by omaremad
why not use arrases function


core::vector3df getTargetAngle(core::vector3df v, core::vector3df r)
{
#define PI 3.14159265358979323846
//v -position
//r -target

core::vector3df angle;
float x,y,z;
x = r.X - v.X;
y = r.Y - v.Y;
z = r.Z - v.Z;

//angle in X-Z plane
angle.Y = atan2 (x, z);
angle.Y *= (180 / PI); //converting from rad to degrees

//angle.Y-=90;
//just making sure angle is somewhere between 0-360 degrees
if(angle.Y < 0) angle.Y += 360;
if(angle.Y >= 360) angle.Y -= 360;

//angle in Y-Z plane while Z and X axes are already rotated around Y
float z1 = sqrt(x*x + z*z);

angle.X = atan2 (z1, y);
angle.X *= (180 / PI); //converting from rad to degrees

//angle.X -= 90;
//just making sure angle is somewhere between 0-360 degrees
if(angle.X < 0) angle.X += 360;
if(angle.X >= 360) angle.X -= 360;


return angle;

}


look at the wiki there are 2 ai classes there

Posted: Wed Sep 07, 2005 2:22 pm
by lor
Ok, thnx it worked !!
By the way, I know about those classes on wiki, I have seen one of them and studiet it. But I simply want to learn something and not only download the class :wink: