PitchTo()

Moderator: GZDoom Developers

User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
Contact:

PitchTo()

Post by Matt »

This could be done by other means, but it would be nice not to have to do a distance calculation and arctangent lookup in the VM.
User avatar
Major Cooke
Posts: 8170
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: PitchTo()

Post by Major Cooke »

Specifically? Towards another actor or towards a point?
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
Contact:

Re: PitchTo()

Post by Matt »

AngleTo() is towards an actor but arbitrary point would be nice! (and preferable)

It really is just atan( (pos.z-other.pos.z) / distance2d(other)), but now that I type this out it does seem like quite a few VM instructions.
User avatar
Apeirogon
Posts: 1605
Joined: Mon Jun 12, 2017 12:57 am

Re: PitchTo()

Post by Apeirogon »

Matt wrote:atan( (pos.z-other.pos.z) / distance2d(other))
"Why walk, if you could ride astride?" Silt Strider chasseur quote

Code: Select all

extend class Actor
{
	void A_PosAttack()
	{
		if (target)
		{
			A_FaceTarget();
			double ang = angle;
			double slope = AimLineAttack(ang, MISSILERANGE);
			A_PlaySound("grunt/attack", CHAN_WEAPON);
			ang  += Random2[PosAttack]() * (22.5/256);
			int damage = Random[PosAttack](1, 5) * 3;
			LineAttack(ang, MISSILERANGE, slope, damage, "Hitscan", "Bulletpuff");
		}
	}
User avatar
Major Cooke
Posts: 8170
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: PitchTo()

Post by Major Cooke »

...What was the point of your post?

Anyway, Matt, one thing you could do in the mean time is use A_Face and set the angle limit to something non-zero.
User avatar
Apeirogon
Posts: 1605
Joined: Mon Jun 12, 2017 12:57 am

Re: PitchTo()

Post by Apeirogon »

All defined in zscript, inside gzdoom pack, hitscan enemy use "aim line attack" to get slope/pitch to it target, not arctangent of distance and positions.
So, I think, this is the quickest way to get pitch/slope to some actor.
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
Contact:

Re: PitchTo()

Post by Matt »

Major Cooke wrote:Anyway, Matt, one thing you could do in the mean time is use A_Face and set the angle limit to something non-zero.
That's pretty much what I'm doing now - storing a backup pitch and angle, calling A_Face, recording the new pitch and resetting the pitch and angle.
User avatar
Gutawer
Posts: 469
Joined: Sat Apr 16, 2016 6:01 am
Preferred Pronouns: She/Her

Re: PitchTo()

Post by Gutawer »

You can do this via something like this:

Code: Select all

Vector3 dirTo = vec3To(other).unit();
double angleTo = atan2(dirTo.y, dirTo.x);
double pitchTo = -asin(dirTo.z);
You can of course take out the angleTo line if it's unnecessary.
User avatar
Major Cooke
Posts: 8170
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: PitchTo()

Post by Major Cooke »

He's trying to have this be made done on the engine side to reduce calculations on the VM side, correct me if I'm wrong.
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
Contact:

Re: PitchTo()

Post by Matt »

That is correct.
argv
Posts: 184
Joined: Tue Aug 30, 2016 4:47 pm

Re: PitchTo()

Post by argv »

I've submitted pull request #553 which, if merged, will do what you need. See forum post for an example.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49056
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: PitchTo()

Post by Graf Zahl »

I'd rather do this natively for performance reasons.
User avatar
Apeirogon
Posts: 1605
Joined: Mon Jun 12, 2017 12:57 am

Re: PitchTo()

Post by Apeirogon »

Before try to make something like this I wonder does distance(2/3)d more performance wise than cos/sin(arctan(number) )?
Accensus
Posts: 2383
Joined: Thu Feb 11, 2016 9:59 am

Re: PitchTo()

Post by Accensus »

Bumperino. Will this get added natively or will it remain DIY?
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
Contact:

Re: PitchTo()

Post by Matt »

Would it even make a performance difference anymore nowadays?
Post Reply

Return to “Closed Feature Suggestions [GZDoom]”