VectorAngle returning wrong numbers?

Bugs that have been investigated and resolved somehow.

Moderator: GZDoom Developers

Forum rules
Please don't bump threads here if you have a problem - it will often be forgotten about if you do. Instead, make a new thread here.
Post Reply
User avatar
jpalomo
Posts: 772
Joined: Mon May 17, 2010 9:45 am

VectorAngle returning wrong numbers?

Post by jpalomo »

One of the recent updates seems to have broken one of my mods horribly (more specifically, this one). Basically, the acs script calculates the angle and pitch between you and a target and forces you to face them. Here is a relevant function used in the script:

Code: Select all

Function Int Pitch (Int tid1, Int tid2)
{
    Int x, y, z, xy;
    x = GetActorX(tid2) - GetActorX(tid1);
    y = GetActorY(tid2) - GetActorY(tid1);
    z = GetActorZ(tid2) - GetActorZ(tid1);
    xy = VectorLength (x, y);
    return -VectorAngle(xy, z);
}
This is actually a slightly altered version of [wiki]GetTargetPitch[/wiki] found in the [wiki=Other_useful_functions]other useful functions[/wiki] page. The expected result from this is a pitch that is used as your new view pitch. In recent git versions, if you happen to be above an enemy when you use this, it alters your pitch so you are looking at the ceiling. This worked perfectly fine in 2.8.1.

To test, bind a key to user2, aim at a monster, then press user2 and keep them in line-of-sight while you move around them.
User avatar
NeuralStunner
 
 
Posts: 12328
Joined: Tue Jul 21, 2009 12:04 pm
Preferred Pronouns: No Preference
Operating System Version (Optional): Windows 11
Graphics Processor: nVidia with Vulkan support
Location: capital N, capital S, no space
Contact:

Re: VectorAngle returning wrong numbers?

Post by NeuralStunner »

Does it work if you use the source GetTargetPitch script as-is? There's a chunk of that missing, which I'm guessing deals with the quirks of pitch range. (0 is straight ahead, 90 is straight down, 270 is straight up.)
User avatar
KeksDose
 
 
Posts: 596
Joined: Thu Jul 05, 2007 6:13 pm
Location: my laboratory
Contact:

Re: VectorAngle returning wrong numbers?

Post by KeksDose »

Looks like a ChangeActorPitch change to me. VectorAngle appears to return the same values in zdoom 2.8.1 and zdoom 2.9pre-1075-g4899c40. Keep in mind as you are above the target, the calculated pitch is in the [0.75, 1.0) range, while ChangeActorPitch takes a range of [-0.25, 0.25]. Perhaps a change was made to clamp values inside of that range, so 0.9 is no longer equivalent to -0.1?

The two scripts are equivalent, the difference being just how the horizontal distance is being calculated. It uses branching to avoid imprecision, division by 0 and returning a negative distance, otherwise, it is just SOH-CAH-TOA applied.
User avatar
Nash
 
 
Posts: 17492
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Re: VectorAngle returning wrong numbers?

Post by Nash »

User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49230
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: VectorAngle returning wrong numbers?

Post by Graf Zahl »

No. This looks like a fixed point overflow that no longer happens with floating point calculations.
User avatar
jpalomo
Posts: 772
Joined: Mon May 17, 2010 9:45 am

Re: VectorAngle returning wrong numbers?

Post by jpalomo »

If thats the case, this can probably be closed as [user error] or [not a bug] then, right? What changes would I need to make to my project to fix it for git builds without breaking it for older versions?
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49230
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: VectorAngle returning wrong numbers?

Post by Graf Zahl »

Before this gets closed I need to check the particular case that fails. Do you have something smaller to test?
User avatar
jpalomo
Posts: 772
Joined: Mon May 17, 2010 9:45 am

Re: VectorAngle returning wrong numbers?

Post by jpalomo »

I never saw your response. Oops! I fixed it on my end with this:

Code: Select all

Function Int Pitch (Int tid1, Int tid2)
{
	Int p, x, y, z, xy;
	x = GetActorX(tid2) - GetActorX(tid1);
	y = GetActorY(tid2) - GetActorY(tid1);
	z = GetActorZ(tid2) - GetActorZ(tid1);
	xy = VectorLength (x, y);
	p = -VectorAngle(xy, z);
	If (p < -0.25)
		p += 1.0;
    return p;
}
This solved the issue in my specific case, and it doesn't cause any issues in older ZDoom versions. I don't have anything else that you can test it with unfortunately. I wonder if any other mods relied on the fixed point overflow? Hopefully none. This can be closed.
Post Reply

Return to “Closed Bugs [GZDoom]”