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
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, alibaba), 1,426 guests, and 9 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19055 Registered Users
Previous Thread
Next Thread
Print Thread
Rating: 3
Page 1 of 2 1 2
turn entity smoothly around its axis to face another entity #258360
03/30/09 00:50
03/30/09 00:50
Joined: Jan 2005
Posts: 605
Deutschland, NRW
G
garv3 Offline OP
User
garv3  Offline OP
User
G

Joined: Jan 2005
Posts: 605
Deutschland, NRW
Hi all,

I'm trying to turn an entity around its axis smoothly. It is supposed to turn towards another entity and take the shortest rotation direction.
Here is some code:
Code:
vec_set(temp, my.x);
	vec_sub(temp, vector(mein_ziel_ptr.x,mein_ziel_ptr.y,mein_ziel_ptr.z+mein_ziel_ptr.gegner_hoehe));
	vec_to_angle(temp_angle, temp);
	if((temp_angle.pan-90)%360 < auge.pan%360 && (temp_angle.pan-90)%360 > (auge.pan - 180)%360){
		auge.pan += 2*time_step;
	}
	if((temp_angle.pan-90)%360 > auge.pan%360 && (temp_angle.pan-90)%360 <= (auge.pan + 180)%360){
		auge.pan -= 2*time_step;
	}
The "auge"-entity is the one that should rotate and "mein_ziel_ptr" is the one that should be faced.
I just don't understand how to work right with the modulo operator and how to avoid problems when the angle is negative...

Help is apreciated!

THX!!!


GameStudio Version: A7 Pro v7.86
Re: turn entity smoothly around its axis to face another entity [Re: garv3] #258372
03/30/09 03:25
03/30/09 03:25
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Replace ALL the above with this (untested).
Should rotate (the shortest direction) to aim at mein_ziel_ptr.
Code:
vec_diff(temp, my.x, vector(mein_ziel_ptr.x,mein_ziel_ptr.y,mein_ziel_ptr.z+mein_ziel_ptr.gegner_hoehe));
vec_to_angle(temp_angle, temp);
my.pan += (ang(temp_angle.pan) * time_step);  //maybe (temp_angle.pan* time_step * 2) for speed of rotation
//optional  my.tilt += (ang(temp_angle.tilt) * time_step); 






"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: turn entity smoothly around its axis to face another entity [Re: EvilSOB] #258383
03/30/09 06:30
03/30/09 06:30
Joined: Aug 2004
Posts: 1,345
Kyiv, Ukraine
VeT Offline

Serious User
VeT  Offline

Serious User

Joined: Aug 2004
Posts: 1,345
Kyiv, Ukraine
Code:
void BotTurnTo(ENTITY* ent, VECTOR* targ_vec)
{
	var temp[3];
	
	vec_diff(temp,ent.x,targ_vec);
	vec_to_angle(targ_vec,temp);
	
	ent.pan -= sign(ang(180 + ent.pan - targ_vec.x)) * 5 * time_step;
}


tested one

Last edited by VeT; 04/02/09 13:04.

1st prize: Lite-C and Newton 2.17 by Vasilenko Vitaliy

Newton2 videos: http://tinyurl.com/NewtonVideos
LiteC+Newton2 discussion: http://tinyurl.com/NewtonWrapperDiscussion
Latest LiteC+Newton2 version(v23, from 29.10.2009): http://depositfiles.com/files/ae1l0tpro
Re: turn entity smoothly around its axis to face another entity [Re: VeT] #258396
03/30/09 11:00
03/30/09 11:00
Joined: Jan 2005
Posts: 605
Deutschland, NRW
G
garv3 Offline OP
User
garv3  Offline OP
User
G

Joined: Jan 2005
Posts: 605
Deutschland, NRW
Thx VeT!

There is a tiny error in your script. In line 3 you must replace the 'my' pointer by 'ent'.
But with some modifications it works fine for me!
Thank you!


GameStudio Version: A7 Pro v7.86
Re: turn entity smoothly around its axis to face another entity [Re: garv3] #258404
03/30/09 12:57
03/30/09 12:57
Joined: Aug 2004
Posts: 1,345
Kyiv, Ukraine
VeT Offline

Serious User
VeT  Offline

Serious User

Joined: Aug 2004
Posts: 1,345
Kyiv, Ukraine
hm... really


1st prize: Lite-C and Newton 2.17 by Vasilenko Vitaliy

Newton2 videos: http://tinyurl.com/NewtonVideos
LiteC+Newton2 discussion: http://tinyurl.com/NewtonWrapperDiscussion
Latest LiteC+Newton2 version(v23, from 29.10.2009): http://depositfiles.com/files/ae1l0tpro
Re: turn entity smoothly around its axis to face another entity [Re: VeT] #258624
03/31/09 22:52
03/31/09 22:52
Joined: Jul 2005
Posts: 192
Orange County
S
silencer Offline
Member
silencer  Offline
Member
S

Joined: Jul 2005
Posts: 192
Orange County
I think the below works too, from the manual:

Code:
function turn_towards_target()
{
  var temp1;
	
  vec_set(temp1,player.x); 
  vec_sub(temp1,someAgent.x);
  vec_to_angle(someAgent.pan,temp1); 
  
} 


Though I'm unsure how to make the rotation be tied to a "time_step".


AMD 64 x2 4400+ 2048mb DDR3200 NVidia 6800GS 256mb Soundblaster Audigy 2 A7 Commercial 7.07
Re: turn entity smoothly around its axis to face another entity [Re: silencer] #258844
04/02/09 13:06
04/02/09 13:06
Joined: Aug 2004
Posts: 1,345
Kyiv, Ukraine
VeT Offline

Serious User
VeT  Offline

Serious User

Joined: Aug 2004
Posts: 1,345
Kyiv, Ukraine
yes, it would work, but it isnt smooth wink

compare with my example: i replace vec_set and vec_sub with vec_diff and add smooth rotation ent.pan -= sign ***


1st prize: Lite-C and Newton 2.17 by Vasilenko Vitaliy

Newton2 videos: http://tinyurl.com/NewtonVideos
LiteC+Newton2 discussion: http://tinyurl.com/NewtonWrapperDiscussion
Latest LiteC+Newton2 version(v23, from 29.10.2009): http://depositfiles.com/files/ae1l0tpro
Re: turn entity smoothly around its axis to face another entity [Re: VeT] #258857
04/02/09 14:41
04/02/09 14:41
Joined: Dec 2003
Posts: 1,225
germany
gri Offline
Serious User
gri  Offline
Serious User

Joined: Dec 2003
Posts: 1,225
germany
hi,

thanx VeT, very short and fine.
But what if the camera.tilt needs to get changed too?



,gri


"Make a great game or kill it early" (Bruce Shelley, Ensemble Studios)
Re: turn entity smoothly around its axis to face another entity [Re: gri] #258862
04/02/09 15:39
04/02/09 15:39
Joined: Aug 2004
Posts: 1,345
Kyiv, Ukraine
VeT Offline

Serious User
VeT  Offline

Serious User

Joined: Aug 2004
Posts: 1,345
Kyiv, Ukraine
looking like you would need something like

Code:
ent.pan -= sign(ang(180 + ent.pan - targ_vec.x)) * 5 * time_step;
ent.tilt -= sign(ang(45 + ent.tilt - targ_vec.y)) * 5 * time_step;
ent.roll -= sign(ang(180 + ent.roll - targ_vec.z)) * 5 * time_step;

untested

play with 45 in tilt as it changes from -90 to 90... mmm, 0 is also a variant wink


1st prize: Lite-C and Newton 2.17 by Vasilenko Vitaliy

Newton2 videos: http://tinyurl.com/NewtonVideos
LiteC+Newton2 discussion: http://tinyurl.com/NewtonWrapperDiscussion
Latest LiteC+Newton2 version(v23, from 29.10.2009): http://depositfiles.com/files/ae1l0tpro
Re: turn entity smoothly around its axis to face another entity [Re: VeT] #258887
04/02/09 18:01
04/02/09 18:01
Joined: Sep 2007
Posts: 52
Tver,Russia
D
dtntr Offline
Junior Member
dtntr  Offline
Junior Member
D

Joined: Sep 2007
Posts: 52
Tver,Russia
This is realy smooth!
Code:
vec_set (temp_enemy_rotate.x, destination_node.x); 
vec_sub (temp_enemy_rotate.x, my.x);
vec_to_angle (temp_enemy_rotate_2.x, temp_enemy_rotate.x);
if(my.pan == temp_enemy_rotate_2.x)
{
my.pan=my.pan;
}
else
{
rotate_result = ang(temp_enemy_rotate_2.x - my.pan);
if (rotate_result > 0)my.pan += 20 * time_step;
if (rotate_result < 0)my.pan -= 20 * time_step; 
if ((ang(temp_enemy_rotate_2.x - my.pan) < 0) && (rotate_result > 0))	my.pan = temp_enemy_rotate_2.x; 
if ((ang(temp_enemy_rotate_2.x - my.pan) > 0) && (rotate_result < 0))	my.pan = temp_enemy_rotate_2.x; 


Page 1 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

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