Massassi Forums Logo

This is the static archive of the Massassi Forums. The forums are closed indefinitely. Thanks for all the memories!

You can also download Super Old Archived Message Boards from when Massassi first started.

"View" counts are as of the day the forums were archived, and will no longer increase.

ForumsCog Forum → Autoaiming with FirstThingInView()
Autoaiming with FirstThingInView()
2002-09-25, 11:38 PM #1
I tried to implement some autoaiming using this code:
Code:
potential = FirstThingInView(player, 100, 1, 0x404);
while(potential != -1)
{
	if((HasLOS(player, potential)) && (potential != player) && (VectorDist(GetThingPos(player), GetThingPos(potential)) <= 1))
	{
		temp = VectorSub(GetThingPos(potential), GetThingPos(player));
		autoaim = VectorSet(VectorZ(temp), VectorX(temp), 0);
		FireProjectile(player, projectile, -1, 8, '0.0135 0.1624 0', autoaim, 1, 0x20, 0, 0);
	}
	potential = NextThingInView();
}

But it does not work. See any mistakes?

------------------
"Häb Pfrässe, süsch chlepfts!" - The coolest language in the world (besides Cherokee)

[This message has been edited by zagibu (edited September 26, 2002).]
"Häb Pfrässe, süsch chlepfts!" - The coolest language in the world (besides Cherokee)
2002-09-26, 12:14 AM #2
Another try:
Code:
potential = FirstThingInView(player, 100, 1, 0x404);
while(potential != -1)
{
	if((HasLOS(player, potential)) && (potential != player) && (VectorDist(GetThingPos(player), GetThingPos(potential)) <= 1))
	{
		temp = VectorSub(GetThingPos(potential), VectorAdd('0.0135 0.1624 0', GetThingPos(player)));
		temp = VectorNorm(temp);
		dummy = FireProjectile(player, projectile, -1, 8, '0.0135 0.1624 0', '0 0 0', 1, 0x20, 0, 0);
		SetThingLook(dummy, temp);
		SetThingVel(dummy, VectorScale(temp, 10));
	}
	potential = NextThingInView();
}

It works this time. But it's not accurate enough at times. See any errors?

------------------
"Häb Pfrässe, süsch chlepfts!" - The coolest language in the world (besides Cherokee)

[This message has been edited by zagibu (edited September 26, 2002).]
"Häb Pfrässe, süsch chlepfts!" - The coolest language in the world (besides Cherokee)
2002-09-26, 5:41 AM #3
Maybe I should ask Hideki, he has a similar thing done in EHP 2.1...

------------------
"Häb Pfrässe, süsch chlepfts!" - The coolest language in the world (besides Cherokee)
"Häb Pfrässe, süsch chlepfts!" - The coolest language in the world (besides Cherokee)
2002-09-26, 6:32 AM #4
Yeah, I see errors. [http://forums.massassi.net/html/smile.gif]

From the first example:
Code:
FireProjectile(player, projectile, -1, 8, '0.0135 0.1624 0', autoaim, 1, 0x20, 0, 0);

That param isn't for auto-aiming, it's for 2d auto-aim error. The auto-aiming is controlled by the last two parameters. The 0x20 Proj Flag enables auto-aim, but because you have 0 values for the two axes, JK will have trouble aiming the projectile - you probably won't see it.

Code:
autoaim = VectorSet(VectorZ(temp), VectorX(temp), 0);

You can't just pick any two axes for auto-aim. Although aiming is 2d, it's in 3d space. Just use JK's auto-aim params. As in:

Code:
FireProjectile(parent, tpl, -1, -1, offset, error, extra_flex, flags, AA_FOVX, AA_FOVZ);


------------------
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.

[This message has been edited by SaberMaster (edited September 26, 2002).]
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
2002-09-26, 7:27 AM #5
I see what you mean, but that's not the problem. Ever played RtcW? I try to recreate the lightning gun, which hits any target within range and a certain FOV. I can't use the standard autoaim parameters, because they don't work in multiplayer. And meanwhile I know that the errorvec can't be used for such a task. The second approach works, but it is somehow not accurate enough...

------------------
"Häb Pfrässe, süsch chlepfts!" - The coolest language in the world (besides Cherokee)

[This message has been edited by zagibu (edited September 26, 2002).]
"Häb Pfrässe, süsch chlepfts!" - The coolest language in the world (besides Cherokee)
2002-09-26, 8:31 AM #6
With the 0x60 Projectile Flags, auto-aim does work in multiplayer.

------------------
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.

[This message has been edited by SaberMaster (edited September 26, 2002).]
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
2002-09-26, 9:47 AM #7
Hmm. Do you still have to set it on in the menu or does it work anyway?

------------------
"Häb Pfrässe, süsch chlepfts!" - The coolest language in the world (besides Cherokee)
"Häb Pfrässe, süsch chlepfts!" - The coolest language in the world (besides Cherokee)
2002-09-27, 2:20 AM #8
It doesn't work when the menuoption is off.

------------------
"Häb Pfrässe, süsch chlepfts!" - The coolest language in the world (besides Cherokee)
"Häb Pfrässe, süsch chlepfts!" - The coolest language in the world (besides Cherokee)
2002-09-27, 5:34 AM #9
Hmmm. No, auto-aim probably wouldn't work if you want to fire multiple projectiles at the same time.

From your second example:
Code:
temp = VectorSub(GetThingPos(potential), VectorAdd('0.0135 0.1624 0', GetThingPos(player)));
temp = VectorNorm(temp);
dummy = FireProjectile(player, projectile, -1, 8, '0.0135 0.1624 0', '0 0 0', 1, 0x20, 0, 0);
SetThingLook(dummy, temp);
SetThingVel(dummy, VectorScale(temp, 10));

First, you don't need to reset the thing's velocity. If the lightning is instant, then it won't use a velocity.

Second, FireProjectile()'s offset is not added to the player's position like that. The offset goes in the direction of the player's torso lvec. Otherwise, pitching would make the projectile appear to be created at the wrong position.

I suspect that's why it isn't accurate. Try calculating the lvec like this:
Code:
dummy = FireProjectile(player, projectile, -1, 8, '0.0135 0.1624 0', '0 0 0', 0, 0, 0, 0);
lvec=VectorSub(GetThingPos(potential), GetThingPos(dummy));
SetThingLook(dummy, lvec);


------------------
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
2002-09-27, 9:15 AM #10
Yey, it works. I bow before you, my master.

------------------
"Häb Pfrässe, süsch chlepfts!" - The coolest language in the world (besides Cherokee)
"Häb Pfrässe, süsch chlepfts!" - The coolest language in the world (besides Cherokee)

↑ Up to the top!