|
Smooth turn problem
#365672
03/28/11 13:31
03/28/11 13:31
|
Joined: Dec 2010
Posts: 87
romin2011
OP
Junior Member
|
OP
Junior Member
Joined: Dec 2010
Posts: 87
|
Hello! this is the second time i am asking help for my problem to turn the entities smothly toward the target, i hope someone would solve it this time. Here is my code... The commented lines of code are those nonworking codes that some people told me to try last time but didn't work. the ent_faceto & ent_turnto works but bcoz of wait_for() it freezes the rest of the code until it turns to the target.
if(my.state==reachcover)
{
if ((c_scan(my.x, my.pan, vector(360, 60, 5000), IGNORE_ME | IGNORE_FLAG2 | SCAN_LIMIT) > 0) && (you.state == coverplace ))
{
dummy=you;
// ent_turnto & ent_faceto freezes the code till it turns toward target
// ent_faceto(me,dummy.x,1);
// wait_for(ent_faceto);
//it doesn't work too the entity runs toward random directions.
// if(abs(ang(dummy-my.pan)) > 1)
// {
// my.pan += clamp(ang(dummy-my.pan),-5,5)*time_step;
// }
// else // your entity faces now the desired direction
// {
vec_set(a,dummy.x);
vec_sub(a,my.x);
vec_to_angle(my.pan,a);
c_move (my, vector(8*time_step,0,0), nullvector, GLIDE | IGNORE_PASSABLE);
ent_animate(my, "run", my.animation, ANM_CYCLE);
my.animation += 8 * time_step;
if(vec_dist(my.x,dummy.x)<1)
{
my.state=iamincover;
set(dummy,FLAG2);
}
// }
}
}
Someone please find a solution. Thank You
|
|
|
Re: Smooth turn problem
[Re: romin2011]
#365676
03/28/11 13:57
03/28/11 13:57
|
Joined: Sep 2003
Posts: 6,861 Kiel (Germany)
Superku
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
|
Replace
vec_set(a,dummy.x); vec_sub(a,my.x); vec_to_angle(my.pan,a);
with
vec_diff(a,dummy.x,my.x); vec_to_angle(b,a); my.pan += ang(b.x-my.pan)*0.5*time_step;
Be aware that you will need a second vector ("b"). If the entity still turns to fast, try different values than 0.5 or use clamp:
vec_diff(a,dummy.x,my.x); vec_to_angle(b,a); my.pan += clamp(ang(b.x-my.pan)*0.5,-5,5)*time_step;
and play with the limit of 5.
"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: Smooth turn problem
[Re: romin2011]
#365688
03/28/11 15:12
03/28/11 15:12
|
Joined: Sep 2003
Posts: 6,861 Kiel (Germany)
Superku
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
|
You're welcome! can i also check inside an if condition weather the entity reached the target angle? if(abs(ang(b.x-my.pan)) < 1) { entity faces target } That should do the trick.
"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
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|