If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Guest
Post
by Guest » Sun Sep 04, 2005 4:04 pm
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:
there are no errors, but it doesn't work. How to make bot look at me ??
CZestmyr
Posts: 72 Joined: Sat Feb 12, 2005 7:11 pm
Location: Czech Republic
Contact:
Post
by CZestmyr » Sun Sep 04, 2005 6:59 pm
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...
lor
Posts: 22 Joined: Sat Aug 27, 2005 2:07 pm
Post
by lor » Mon Sep 05, 2005 2:34 pm
I forgot to log in. Sorry. Ok,vec.getHorizontalAngle(); doesn't work..
check it out :
'class irr::core::vector3df' has no member named 'GetHorizontalAngle'
so how to do it if this doesn't work ??
lor
Posts: 22 Joined: Sat Aug 27, 2005 2:07 pm
Post
by lor » Mon Sep 05, 2005 2:34 pm
I forgot to log in. Sorry. Ok, doesn't work..
vec.getHorizontalAngle();
check it out :
'class irr::core::vector3df' has no member named 'GetHorizontalAngle'
so how to do it if this doesn't work ??
lor
Posts: 22 Joined: Sat Aug 27, 2005 2:07 pm
Post
by lor » Mon Sep 05, 2005 2:36 pm
I forgot to log in. Sorry. Ok,vec.getHorizontalAngle(); doesn't work..
check it out :
'class irr::core::vector3df' has no member named 'GetHorizontalAngle'
so how to do it if this doesn't work ??
CZestmyr
Posts: 72 Joined: Sat Feb 12, 2005 7:11 pm
Location: Czech Republic
Contact:
Post
by CZestmyr » Mon Sep 05, 2005 5:27 pm
It must work. At least it causes no problem on my compoter
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...
lor
Posts: 22 Joined: Sat Aug 27, 2005 2:07 pm
Post
by lor » Tue Sep 06, 2005 6:09 pm
and are you sure, you used vector3df ?? I use the same version, and I tried using G for g
evo
Posts: 96 Joined: Mon Jun 27, 2005 6:46 pm
Location: The Netherlands
Post
by evo » Tue Sep 06, 2005 8:04 pm
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);
omaremad
Competition winner
Posts: 1027 Joined: Fri Jul 15, 2005 11:30 pm
Location: Cairo,Egypt
Post
by omaremad » Tue Sep 06, 2005 9:29 pm
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
lor
Posts: 22 Joined: Sat Aug 27, 2005 2:07 pm
Post
by lor » Wed Sep 07, 2005 2:22 pm
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