Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (AndrewAMD, gamers, Kingware, AemStones), 1,578 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
LucasJoshua, Baklazhan, Hanky27, firatv, wandaluciaia
19054 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Smooth turn problem #365672
03/28/11 13:31
03/28/11 13:31
Joined: Dec 2010
Posts: 87
R
romin2011 Offline OP
Junior Member
romin2011  Offline OP
Junior Member
R

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.

Code:
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] #365674
03/28/11 13:46
03/28/11 13:46
Joined: Dec 2010
Posts: 87
R
romin2011 Offline OP
Junior Member
romin2011  Offline OP
Junior Member
R

Joined: Dec 2010
Posts: 87
And this function by a user of the forum doesn't work either. The entity starts turning toward the target then runs and turns randomly???

Code:
VECTOR temp_vec;
int botturnto(ENTITY* ent, VECTOR* targ_vec)
{
	vec_diff(temp_vec.x,my.x,targ_vec.x);
	vec_to_angle(targ_vec.x,temp_vec.x);
	ent.pan -= sign(ang(180+ent.pan - targ_vec.x))*5*time_step;
}


// And the call to the function
botturnto(me,dummy.x);



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 Offline
Senior Expert
Superku  Offline
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: Superku] #365684
03/28/11 14:44
03/28/11 14:44
Joined: Dec 2010
Posts: 87
R
romin2011 Offline OP
Junior Member
romin2011  Offline OP
Junior Member
R

Joined: Dec 2010
Posts: 87
Thank you very much superku you are always helpful. It is working like a charm,
can i also check inside an if condition weather the entity reached the target angle? I mean what to wright inside if() in that case? thank you again.

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 Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
You're welcome!
Quote:
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

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1