[ACS] Force player to look at enemy?

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!)
Post Reply
User avatar
Recurracy
Posts: 558
Joined: Fri Dec 19, 2008 12:11 pm

[ACS] Force player to look at enemy?

Post by Recurracy »

Hi,

My wad is stupid, dumb and you shouldn't play it, period. To make it worse, I came up with this horrible idea. What I'd like to do is have a certain enemy force the player to look at them, zoom in, and play a sound while it's in their FOV. How could I do this?
User avatar
KeksDose
 
 
Posts: 596
Joined: Thu Jul 05, 2007 6:13 pm
Location: my laboratory
Contact:

Re: [ACS] Force player to look at enemy?

Post by KeksDose »

You may recover the yaw and pitch like so with the player as the activator. The last minus sign comes from view pitch being reversed from world pitch.

Code: Select all

int x_diff = GetActorX(target) - GetActorX(0);
int y_diff = GetActorY(target) - GetActorY(0);
int z_diff = GetActorZ(target) - GetActorZ(0); // looks good in general...

int facing_ang  =  VectorAngle(x_diff, y_diff);
int facing_vang = -VectorAngle(VectorLength(x_diff, y_diff), z_diff);

// alternative z_diff:
int view_target_z = GetActorZ(target) + GetActorProperty(target, APROP_HEIGHT) / 2;
int viewer_z      = GetActorZ(0) + GetActorProperty(0, APROP_VIEWHEIGHT);
int z_diff        = view_target_z - viewer_z;
// will make the activator face towards the target's centre.    
User avatar
Recurracy
Posts: 558
Joined: Fri Dec 19, 2008 12:11 pm

Re: [ACS] Force player to look at enemy?

Post by Recurracy »

This is all acs?
User avatar
ramon.dexter
Posts: 1562
Joined: Tue Oct 20, 2015 12:50 pm
Graphics Processor: nVidia with Vulkan support
Location: Kozolupy, Bohemia

Re: [ACS] Force player to look at enemy?

Post by ramon.dexter »

Looks like ACS to me.
Post Reply

Return to “Scripting”