Jump to content
johnnyboy

weaponDirection and vectorMultiply question

Recommended Posts

weaponDirection in the wiki gives this example:

bob = createGroup east createUnit ["O_Soldier_F", [0,0,0], [], 0, "NONE"];
bob setVehiclePosition [player modelToWorld [0,100,0], [], 0, "NONE"];
onEachFrame
{
	_beg = ASLToAGL eyePos bob;
	_endE = (_beg vectorAdd (eyeDirection bob vectorMultiply 100));
	drawLine3D [ _beg, _endE, [0,1,0,1]];
	_endW = (_beg vectorAdd (bob weaponDirection currentWeapon bob vectorMultiply 100));
	drawLine3D [_beg, _endW, [1,0,0,1]];
};

I don't understand vectors.  What does the "vectorMultiply 100" achieve in the above code?  Please explain.

 

My goal is to use weaponDirection to determine when an AI is pointing his weapon at a particular object.  This would be the AI unit equivalent to cursorTarget for a player (when player is aiming his weapon, not just looking).  How do I use weaponDirection to find first object intersected by AI's weapon direction? 

 

Thanks in advance to all you whacky smart guys out there.

Share this post


Link to post
Share on other sites

I don't actually understand vectors so much neither, but you can understand like this: eyeDirection and weaponDirection return somewhere a meter away to a certain direction.

So, if you do unit weaponDirection currentWeapon unit vectorMultiply n, it would fit to get n meters away.

 

For example, when weaponDirection returns [0.3,0.7,0] and if you vectorAdd it to the unit's position, will returns the position where a unit's 30(NNE), a meter away.

What if you vectorMultiply 100 the weaponDirection? You can get it!

(please shh about this explain if you find any errors, i didn't even launch a3 to test it)

  • Thanks 1

Share this post


Link to post
Share on other sites

I don't think you can orient a unit's weapon Y/Z axis. Only the X. The only workaround I use is to attach an invisible sphere to the unit and have the unit doWatch it to achieve it. Figured this is what you might've been leading onto.

  • Thanks 1

Share this post


Link to post
Share on other sites
6 minutes ago, POLPOX said:

For example, when weaponDirection returns [0.3,0.7,0] and if you vectorAdd it to the unit's position, will returns the position where a unit's 30(NNE), a meter away.

What if you vectorMultiply 100 the weaponDirection? You can get it!

Thanks PolPox! I get it now.  So I can use eyePos as a starting position and use weaponDirection & vectorMultiply n to return an end position n meters away, and then use the start/end positions with lineIntersectsObjs to find objects the weapon is pointing at.

Perfect!

Share this post


Link to post
Share on other sites
10 minutes ago, phronk said:

I don't think you can orient a unit's weapon Y/Z axis. Only the X. The only workaround I use is to attach an invisible sphere to the unit and have the unit doWatch it to achieve it. Figured this is what you might've been leading onto.

Yessir, per your good advice, that is exactly what I am doing.  They mostly look at the sphere now, and I was just testing direction to see if they were looking at it, but it wasn't granular enough as weapon wasn't pointing quite right.  With this greater granularity I will know when they are pointing exactly at a 10cm sphere (wait until weapon line intersects sphere).  This is for gun breaching the door jamb.  I'm trying to get them to aim more precisely. 

 

This is unrelated to the weaponDirection question, but I may also use the sphere idea to keep them looking in desired direction while moving.  Currently, once they hear enemies on upper floor that they can't possibly see, they want to run forward with weapons pointed at ceiling which is lame.  I'm going to try attaching the spheres to the units, and then have them dowatch/dotarget them while moving.  I don't know if that will mess with their ability to prioritize targeting real enemies though.  Will find out.

Share this post


Link to post
Share on other sites

If they can hear enemies, playing with doTarget shouldn't be a problem, but you might want to make sure they can still look around every once in a while - you don't want them to ignore or miss visible enemies out of hearing range.

  • Like 1

Share this post


Link to post
Share on other sites
1 hour ago, johnnyboy said:

What does the "vectorMultiply 100" achieve in the above code?

Makes the vector 100x longer

  • Like 1

Share this post


Link to post
Share on other sites

I've been working on a similar AI script; Telling the AI to aim at the globe will make him watch it, then engage any immediate threats in LoS, then aim back at the globe.

  • Like 1

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×