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.
Model Target
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:
just use:
But->setRotation(vector3df(0,faceTarget(But, B), 0));
Now, to move it towards the other object:
Here s is the speed. Just increase/decrease acordingly.
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;
}
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));
Uhm... the code don't work correctly...
But moving in opposite direction of Target and his face direction is not correct...
But moving in opposite direction of Target and his face direction is not correct...
The best italian GM related site
www.gamemaker.it
www.gamemaker.it
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...
Excuse my bad english...
The best italian GM related site
www.gamemaker.it
www.gamemaker.it
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));
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));