2 registered members (AndrewAMD, alibaba),
1,426
guests, and 9
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
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
garv3
OP
User
|
OP
User
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: 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
Expert
|
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.
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: VeT]
#258396
03/30/09 11:00
03/30/09 11:00
|
Joined: Jan 2005
Posts: 605 Deutschland, NRW
garv3
OP
User
|
OP
User
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
Serious User
|
Serious User
Joined: Aug 2004
Posts: 1,345
Kyiv, Ukraine
|
|
|
|
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
silencer
Member
|
Member
Joined: Jul 2005
Posts: 192
Orange County
|
I think the below works too, from the manual: 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: VeT]
#258857
04/02/09 14:41
04/02/09 14:41
|
Joined: Dec 2003
Posts: 1,225 germany
gri
Serious User
|
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)
|
|
|
|