Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
1 registered members (TipmyPip), 18,449 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Facing another object? #323856
05/17/10 21:29
05/17/10 21:29
Joined: May 2010
Posts: 13
J
Jack2010 Offline OP
Newbie
Jack2010  Offline OP
Newbie
J

Joined: May 2010
Posts: 13
Hey guys! I think I read somewhere that it's possible to make an object face another through a vec_ function? I'm unsure about this, but does anyone know if there is such a function or if an example of one exists?

Thanks!

Re: Facing another object? [Re: Jack2010] #323857
05/17/10 21:37
05/17/10 21:37
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Use vec_diff and vec_to_angle (see Manual for detailed information).
VECTOR temp;
...
vec_diff(temp,ent1.x,ent2.x);
vec_to_angle(ent2.pan,temp);
ent2.tilt = 0; //only turn left/right

This code makes ent2 face ent1.


"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: Facing another object? [Re: Superku] #323871
05/17/10 22:18
05/17/10 22:18
Joined: May 2010
Posts: 13
J
Jack2010 Offline OP
Newbie
Jack2010  Offline OP
Newbie
J

Joined: May 2010
Posts: 13
Thanks for the help Superku! Works great, a lot better than what I could have thought of grin.

Re: Facing another object? [Re: Jack2010] #323944
05/18/10 14:58
05/18/10 14:58
Joined: May 2010
Posts: 13
J
Jack2010 Offline OP
Newbie
Jack2010  Offline OP
Newbie
J

Joined: May 2010
Posts: 13
Sorry for the double post, but the edit button isn't working (atleast not on my browser)

Is there a way to slow down the movement of the object to face another (using the code posted by Superku), so the user actually sees the movement instead of the object immediately changing direction?

I'm guessing it would be something like so:

var temp_pan = atan(my_vector.x/my_vector.y); // Copied from manual
var temp_tilt = asin(my_vector.z/length(my_vector)); // ^
var i;
for(i = 0; i < temp_pan; i++)
{
angle.pan += 1;
}
for(i = 0; i < temp_tilt; i++)
{
angle.tilt += 1;
}

Could anyone confirm this? I can't seem to get it working frown.

Thanks!

Re: Facing another object? [Re: Jack2010] #323949
05/18/10 15:35
05/18/10 15:35
Joined: Nov 2009
Posts: 89
Germany, NRW
T
TrackingKeks Offline
Junior Member
TrackingKeks  Offline
Junior Member
T

Joined: Nov 2009
Posts: 89
Germany, NRW
Code:
var temp_pan = atan(my_vector.x/my_vector.y); // Copied from manual
var temp_tilt = asin(my_vector.z/length(my_vector)); // ^
var i;
for(i = 0; i < temp_pan; i++)
{
angle.pan += 1*time_step;
wait(1);
}
for(i = 0; i < temp_tilt; i++)
{
angle.tilt += 1*time_step;
wait(1);
}




Gamestudio: A7.82 Commercial/A8 Commercial
System specs (Laptop):
Windows 7 64bit
DirectX v10.1
Intel Core i7-720QM CPU @ 1,60 GHz
4GB DDR2 Ram
NVIDIA GeForce GT 230M (1024MB)
Re: Facing another object? [Re: TrackingKeks] #323963
05/18/10 17:59
05/18/10 17:59
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
VECTOR temp,temp2;
...
vec_diff(temp,ent1.x,ent2.x);
vec_to_angle(temp2,temp);
ent2.pan += ang(temp2.x-ent2.pan)*0.1*time_step;

Try this. If the entity is turning too fast, replace the last line with the following:

ent2.pan += clamp(ang(temp2.x-ent2.pan)*0.1,-5,5)*time_step;

and adjust the max. speed by replacing 5 with different values.


"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: Facing another object? [Re: Superku] #323968
05/18/10 18:38
05/18/10 18:38
Joined: May 2010
Posts: 13
J
Jack2010 Offline OP
Newbie
Jack2010  Offline OP
Newbie
J

Joined: May 2010
Posts: 13
Thanks guys! I'll try both now wink

Haha, only forum I've found where you can get to the point, helpful and efficient answers grin

Last edited by Jack2010; 05/18/10 18:46.
Re: Facing another object? [Re: Jack2010] #323977
05/18/10 19:29
05/18/10 19:29
Joined: May 2010
Posts: 13
J
Jack2010 Offline OP
Newbie
Jack2010  Offline OP
Newbie
J

Joined: May 2010
Posts: 13
AARGH! The edit button still isn't working frown

Superku, I've just tried your code and nothing seems to happen :S, its probably me doing something wrong. Just to check, ent1 is the object to face and ent2 is the object to face ent1. BTW, should I place my code where you've placed "..."? And does this code still include pan, tilt and roll angles?

Thanks for your answers!!
Jack.

Re: Facing another object? [Re: Jack2010] #323980
05/18/10 19:36
05/18/10 19:36
Joined: Aug 2009
Posts: 1,438
Spain
painkiller Offline
Serious User
painkiller  Offline
Serious User

Joined: Aug 2009
Posts: 1,438
Spain
from the workshops:

Code:
// get the angle to the enemy			
			VECTOR vDirection;
			ANGLE vTargetAngle;
			vec_diff(vDirection,enemy.x,my.x);
			vec_to_angle(vTargetAngle,vDirection);
// vAngle is now the angle to the enemy.		
// Turn right or left depending on the difference
// between the current and the target pan angle			
			my.pan += time_step * sign(ang(vTargetAngle.pan - my.pan));




3D Gamestudio A8 Pro
AMD FX 8350 4.00 Ghz
16GB RAM
Gigabyte GeForce GTX 960 4GB
Re: Facing another object? [Re: painkiller] #323981
05/18/10 19:45
05/18/10 19:45
Joined: May 2010
Posts: 13
J
Jack2010 Offline OP
Newbie
Jack2010  Offline OP
Newbie
J

Joined: May 2010
Posts: 13
Originally Posted By: painkiller
from the workshops:

Code:
// get the angle to the enemy			
			VECTOR vDirection;
			ANGLE vTargetAngle;
			vec_diff(vDirection,enemy.x,my.x);
			vec_to_angle(vTargetAngle,vDirection);
// vAngle is now the angle to the enemy.		
// Turn right or left depending on the difference
// between the current and the target pan angle			
			my.pan += time_step * sign(ang(vTargetAngle.pan - my.pan));



Thanks painkiller! I've just added the following line:
my.tilt += time_step * sign(ang(vTargetAngle.tilt - my.tilt));

and it works perfectly!

Thanks everyone for the help! I'm gonna have to read up more on engine functions wink.


Gamestudio download | 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