Getting an actor to constantly face another

Archive of the old editing forum
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. This forum is archived - please use this set of forums to ask new questions.
Locked
User avatar
Travis
Posts: 79
Joined: Sat Jul 29, 2006 7:09 pm
Contact:

Getting an actor to constantly face another

Post by Travis »

I'm having trouble using setactorangle to get an actor always look at another actor. It probably requires some sort of math equation which I fail too much at to do?
User avatar
LilWhiteMouse
Posts: 2270
Joined: Tue Jul 15, 2003 7:00 pm
Location: Maine, US
Contact:

Post by LilWhiteMouse »

This function makes one actor face another:

Code: Select all

function int face (int facer, int target)
	{
	int x = (GetActorX(target) - GetActorX(facer));
	int y = (GetActorY(target) - GetActorY(facer));
	SetActorAngle(facer, VectorAngle(x, y));
	return 0;
	}
Then just use this in a script to make your actor face another, where TID1 is the tid of the actor you want to turn, and TID2 is the actor you want it to face.

Code: Select all

face(TID1, TID2);
User avatar
Travis
Posts: 79
Joined: Sat Jul 29, 2006 7:09 pm
Contact:

Post by Travis »

Oh wow, that simple, huh? *smacks forehead*

Thanks LWM!
User avatar
Isle
Posts: 687
Joined: Fri Nov 21, 2003 1:30 am
Location: Arizona, USA

Post by Isle »

if you do
function VOID name(args)
you dont have to retrun anything.
User avatar
solarsnowfall
Posts: 1581
Joined: Thu Jun 30, 2005 1:44 am

Post by solarsnowfall »

You know there's absolutely no reason for that function to return a value. I wrote this explicitly for uses like this. The idea was that it returns an angle that you can do whatever you want with.

Code: Select all

Script 1 (VOID)
{
    SetActorAngle (1, GetTargetAngle (1, 2));
}
Where tid 2 is the actor you want tid 1 to look at.
[edit] Damn you Isle!!! :P
User avatar
LilWhiteMouse
Posts: 2270
Joined: Tue Jul 15, 2003 7:00 pm
Location: Maine, US
Contact:

Post by LilWhiteMouse »

Isle wrote:if you do
function VOID name(args)
you dont have to retrun anything.
That's good to know, thanks.
Locked

Return to “Editing (Archive)”