Model Target

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.
Post Reply
i2k

Model Target

Post by i2k »

Hi everyone.
I have one question.Presently explain situation : Signifies so,
assume, one model is found in position (But) 0,0,0, but the
second (B) 20,0,33, What do so that model But was turned
aside B, and what force the object But move in this
direction This MUCH URGENTLY, please help.


Is it Beforehand thanked.
RESPECTFULLY YOURS i2k.
Felipe
Posts: 25
Joined: Thu Jun 10, 2004 9:13 pm
Location: Rio de Janeiro

Post by Felipe »

When you post in a forum in a language that is not your own, you should put 2 versions of the same post, one in english (in this case) and one in your native language. That way it'd be easier to get help. What I understood from your post is, you want to rotate object "but" and point it to object "b". Then you want to move it in that direction. Is that right? Well, if it is,

You can use this function to find the angle on the Y axis to rotate towards:

Code: Select all

float DTR=(180.0f/3.14159265358979323f);
float faceTarget(scene::ISceneNode *obj, scene::ISceneNode *target){
	core::vector3df hp;
	hp=obj->getPosition()-target->getPosition();
	return (float) atan2(hp.Z,hp.X)*DTR;
} 
just use:
But->setRotation(vector3df(0,faceTarget(But, B), 0));

Now, to move it towards the other object:

Code: Select all

vector3df a, p;
int s=10;
a=But->getRotation();
p=But->getPosition();
But->setPosition(vector3df(p.X+cos(a.Y/DTR)*s, 0, p.Z+sin(a.Y/DTR)*s));
Here s is the speed. Just increase/decrease acordingly.
DanyATK
Posts: 32
Joined: Mon Mar 22, 2004 8:40 pm
Location: Italy
Contact:

Post by DanyATK »

Uhm... the code don't work correctly...

But moving in opposite direction of Target and his face direction is not correct...
The best italian GM related site
www.gamemaker.it
DanyATK
Posts: 32
Joined: Mon Mar 22, 2004 8:40 pm
Location: Italy
Contact:

Post by DanyATK »

Asd... I've resolved the problem for the moving direction assigning value -10 at the variable "s" but... I have not resolved the problem of facing direction... I've tryed to rotate the model file... but the problem persist... :(

Excuse my bad english... :roll:
The best italian GM related site
www.gamemaker.it
i2k

Post by i2k »

Shorter, I understood, to whom interesting that here is:

code:
float DTR=(180.0f/3.14159265358979323f);
float faceTarget(scene::ISceneNode *obj, scene::ISceneNode *target){
   core::vector3df hp;
   hp=obj->getPosition()-target->getPosition();
   return (float) atan2(hp.X,hp.Z)*DTR;
}


just use:
But->setRotation(vector3df(0,faceTarget(But, B), 0));


Now, to move it towards the other object:
code:
vector3df a, p;
int s=10;
a=But->getRotation();
p=But->getPosition();
But->setPosition(vector3df(p.X-sin(a.Y/DTR)*s, 0, p.Z-cos(a.Y/DTR)*s));
Post Reply