Page 1 of 1

Model Target

Posted: Wed Jul 07, 2004 5:14 pm
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.

Posted: Wed Jul 07, 2004 7:37 pm
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.

Posted: Thu Jul 08, 2004 1:10 am
by DanyATK
Uhm... the code don't work correctly...

But moving in opposite direction of Target and his face direction is not correct...

Posted: Thu Jul 08, 2004 6:46 pm
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:

Posted: Fri Jul 09, 2004 5:22 pm
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));