[ACS] - Making an actor face the player

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
User avatar
FFFF-RRRR
Posts: 8
Joined: Tue Jun 28, 2022 1:07 pm

[ACS] - Making an actor face the player

Post by FFFF-RRRR »

Good day.

I'm stuck with math here, I'll need help.

There are situations in my project where an actor needs to face the player. (Just by the angle, not the pitch).
I haven't been able to figure out the math. Just setting the angle of the actor to the "inverted" angle of the player (by multiplying it with -1) doesn't produce the right result.

I'm aware of SetActorAngle but I'm unable to figure out how to properly calclate the angle necessary.

Does somebody have an idea how to solve this? Help would be greatly appreciated.
User avatar
Sir Robin
Posts: 392
Joined: Wed Dec 22, 2021 7:02 pm
Graphics Processor: Intel (Modern GZDoom)
Location: Medellin, Colombia

Re: [ACS] - Making an actor face the player

Post by Sir Robin »

quickest way to "invert" an angle is to add (or subtract) 180
User avatar
22alpha22
Posts: 277
Joined: Fri Feb 21, 2014 5:04 pm
Graphics Processor: nVidia with Vulkan support
Location: Montana, USA

Re: [ACS] - Making an actor face the player

Post by 22alpha22 »

Have you tried A_Face with the max_pitch property set to 270?
User avatar
Sir Robin
Posts: 392
Joined: Wed Dec 22, 2021 7:02 pm
Graphics Processor: Intel (Modern GZDoom)
Location: Medellin, Colombia

Re: [ACS] - Making an actor face the player

Post by Sir Robin »

Yeah I was going to suggest A_Face also but I looked at the wiki and it says Zscript only
User avatar
KeksDose
 
 
Posts: 590
Joined: Thu Jul 05, 2007 6:13 pm

Re: [ACS] - Making an actor face the player

Post by KeksDose »

If you need something that works for any actor given a tid, you can do this:

Code: Select all

// assume that the player is the activator.
int diff_x = GetActorX(0) - GetActorX(thing_tid);
int diff_y = GetActorY(0) - GetActorY(thing_tid);
int ang = VectorAngle(diff_x, diff_y);
ang now has the property that SetActorAngle(thing_tid, ang) will make the thing face the activator. For reference, you can do pitch similarly:

Code: Select all

int diff_z = GetActorZ(0) - GetActorZ(thing_tid);
int vang = VectorAngle(VectorLength(diff_x, diff_y), diff_z);
User avatar
FFFF-RRRR
Posts: 8
Joined: Tue Jun 28, 2022 1:07 pm

Re: [ACS] - Making an actor face the player

Post by FFFF-RRRR »

@KeksDose
That works. Thank you for your help!
Sir Robin wrote:quickest way to "invert" an angle is to add (or subtract) 180
That's true. Though I tried it and inverting doesn't do the right thing in this situation.
User avatar
KeksDose
 
 
Posts: 590
Joined: Thu Jul 05, 2007 6:13 pm

Re: [ACS] - Making an actor face the player

Post by KeksDose »

oh yea I forgot to mention! in acs, actor angles are fixed point range, which is 0 to 1.0 with the .0 (1 and 1.0 are not the same here is what I'm saying), so you can reverse angles by adding 0.5.

Return to “Scripting”