0 registered members (),
18,767
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: Facing another object?
[Re: Jack2010]
#323944
05/18/10 14:58
05/18/10 14:58
|
Joined: May 2010
Posts: 13
Jack2010
OP
Newbie
|
OP
Newbie
Joined: May 2010
Posts: 13
|
Sorry for the double post, but the edit button isn't working (atleast not on my browser) Is there a way to slow down the movement of the object to face another (using the code posted by Superku), so the user actually sees the movement instead of the object immediately changing direction? I'm guessing it would be something like so: var temp_pan = atan(my_vector.x/my_vector.y); // Copied from manual var temp_tilt = asin(my_vector.z/length(my_vector)); // ^ var i; for(i = 0; i < temp_pan; i++) { angle.pan += 1; } for(i = 0; i < temp_tilt; i++) { angle.tilt += 1; } Could anyone confirm this? I can't seem to get it working  . Thanks!
|
|
|
Re: Facing another object?
[Re: TrackingKeks]
#323963
05/18/10 17:59
05/18/10 17:59
|
Joined: Sep 2003
Posts: 6,861 Kiel (Germany)
Superku
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
|
VECTOR temp,temp2; ... vec_diff(temp,ent1.x,ent2.x); vec_to_angle(temp2,temp); ent2.pan += ang(temp2.x-ent2.pan)*0.1*time_step;
Try this. If the entity is turning too fast, replace the last line with the following:
ent2.pan += clamp(ang(temp2.x-ent2.pan)*0.1,-5,5)*time_step;
and adjust the max. speed by replacing 5 with different values.
"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual Check out my new game: Pogostuck: Rage With Your Friends
|
|
|
Re: Facing another object?
[Re: Jack2010]
#323977
05/18/10 19:29
05/18/10 19:29
|
Joined: May 2010
Posts: 13
Jack2010
OP
Newbie
|
OP
Newbie
Joined: May 2010
Posts: 13
|
AARGH! The edit button still isn't working  Superku, I've just tried your code and nothing seems to happen :S, its probably me doing something wrong. Just to check, ent1 is the object to face and ent2 is the object to face ent1. BTW, should I place my code where you've placed "..."? And does this code still include pan, tilt and roll angles? Thanks for your answers!! Jack.
|
|
|
Re: Facing another object?
[Re: Jack2010]
#323980
05/18/10 19:36
05/18/10 19:36
|
Joined: Aug 2009
Posts: 1,438 Spain
painkiller
Serious User
|
Serious User
Joined: Aug 2009
Posts: 1,438
Spain
|
from the workshops:
// get the angle to the enemy
VECTOR vDirection;
ANGLE vTargetAngle;
vec_diff(vDirection,enemy.x,my.x);
vec_to_angle(vTargetAngle,vDirection);
// vAngle is now the angle to the enemy.
// Turn right or left depending on the difference
// between the current and the target pan angle
my.pan += time_step * sign(ang(vTargetAngle.pan - my.pan));
3D Gamestudio A8 Pro AMD FX 8350 4.00 Ghz 16GB RAM Gigabyte GeForce GTX 960 4GB
|
|
|
Re: Facing another object?
[Re: painkiller]
#323981
05/18/10 19:45
05/18/10 19:45
|
Joined: May 2010
Posts: 13
Jack2010
OP
Newbie
|
OP
Newbie
Joined: May 2010
Posts: 13
|
from the workshops:
// get the angle to the enemy
VECTOR vDirection;
ANGLE vTargetAngle;
vec_diff(vDirection,enemy.x,my.x);
vec_to_angle(vTargetAngle,vDirection);
// vAngle is now the angle to the enemy.
// Turn right or left depending on the difference
// between the current and the target pan angle
my.pan += time_step * sign(ang(vTargetAngle.pan - my.pan));
Thanks painkiller! I've just added the following line: my.tilt += time_step * sign(ang(vTargetAngle.tilt - my.tilt)); and it works perfectly! Thanks everyone for the help! I'm gonna have to read up more on engine functions  .
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|