Gamestudio Links
Zorro Links
Newest Posts
loading historical data 1st time
by AndrewAMD. 04/14/23 12:54
Trade at bar open
by juanex. 04/13/23 19:43
Bug in Highpass2 filter
by rki. 04/13/23 09:54
Adding Limit Orders For IB
by scatters. 04/11/23 16:16
FisherN
by rki. 04/11/23 08:38
AUM Magazine
Latest Screens
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Hecknex World
Who's Online Now
0 registered members (), 1,012 guests, and 8 spiders.
Key: Admin, Global Mod, Mod
Newest Members
rki, FranzIII, indonesiae, The_Judge, storrealba
18919 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
smooth rotation #402178
05/31/12 02:26
05/31/12 02:26
Joined: Feb 2010
Posts: 886
Random Offline OP
User
Random  Offline OP
User

Joined: Feb 2010
Posts: 886
Here we got the typical "turn_towards_target" code:
Code:
function turn_towards_target()
{
  // get the direction from the entity MY to the entity YOU
  vec_set(temp,your.x); 
  vec_sub(temp,my.x);
  vec_to_angle(my.pan,temp); // now MY looks at YOU
}



I forgotten how to turn the entity smoothly and slowly to it's target.
What was the trick again? confused



Re: smooth rotation [Re: Random] #402179
05/31/12 04:29
05/31/12 04:29
Joined: Jul 2008
Posts: 2,101
Germany
rayp Offline

X
rayp  Offline

X

Joined: Jul 2008
Posts: 2,101
Germany
Code:
VECTOR temp;
  vec_set(temp,your.x); 
  vec_sub(temp,my.x);
  my.pan += clamp(ang(temp-my.pan)*0.5,-25,25)*time_step;

And u can search for ent_turnto in entmove.c if i remember right (sry iam not at home, cant take a quick look).

Edit: So here is what i meant in entmoce.c
Code:
//////////////////////////////////////////////////////////////////
// turn towards an absolute target angle with given angular speed
// use wait_for_my(ent_turnto) for determining when the angle is reached
function ent_turnto(ENTITY* ent,ANGLE* to,var aspeed)
{
	proc_kill2(ent_turnto,ent);
// store the "to" angle for the wait loop - it could be a temporary vector!	
	ANGLE atarget;
	vec_set(atarget,to);
	 
	while(aspeed) {
// calculate the difference between the current and the target angle	
		ANGLE adiff;
		ang_diff(adiff,atarget,ent.pan);
// check if we're already there
		if(vec_length(adiff) <= aspeed*time_step) {
			vec_set(ent.pan,atarget);
			return;
		}
// scale the difference angle by the angular speed, 
// and add it to the entity angle
		vec_normalize(adiff,aspeed*time_step);
		ang_add(ent.pan,adiff);
		wait(1);
	}
}

// turn towards a target position with given speed
// use wait_for_my(ent_turnto) for determining when the angle is reached
function ent_faceto(ENTITY* ent,VECTOR* pos,var aspeed)
{
	if(!ent || !pos) return;
	VECTOR* diff = vec_diff(NULL,pos,ent.x);
	vec_to_angle(diff,diff);
	ent_turnto(ent,diff,aspeed);
}




Last edited by rayp; 06/01/12 13:28.

Acknex umgibt uns...zwischen Dir, mir, dem Stein dort...
"Hey Griswold ... where u gonna put a tree that big ?"
1998 i married my loved wife ... Sheeva from Mortal Kombat, not Evil-Lyn as might have been expected
rayp.flags |= UNTOUCHABLE;

Moderated by  HeelX, Spirit 

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