Jump to content
Sign in to follow this  
bhaz

Turret Direction

Recommended Posts

I'm trying to make a script that will allow an AI squad to pick up and transport a single mortar, which involves using attachTo to place the mortar on the units back.

If a mortar is placed at heading 0, and the gunner jumps in and rotates the mortar facing east, the heading is still returned as 0. Upon placing the mortar on the unit's back, depending on the direction the turret was facing, it ends up in some odd positions.

What I'm trying to figure out is how to find the current direction of the turret so I can rotate it accordingly, or better yet, set the turret's direction. Anyone have any ideas?

Edited by bhaz

Share this post


Link to post
Share on other sites

Never mind, solved it.

You can find out the direction of a turret by comparing the direction between the gunner and his assistant, ie:

_numVectorX = (getPos _objGunner select 0) - (getPos _objAssist select 0);
_numVectorY = (getPos _objGunner select 1) - (getPos _objAssist select 1);
_numDirection = (_numVectorX atan2 _numVectorY) + 108;

When adding 108 (the angle the gunners are on compared to the turret's facing), this will return the compass direction of the turret itself. I'd imagine this could be extended to other vehicles as well.

I ended up going with another idea though, because the nature of my mission means the assistant might get killed, and ensuring there was always two gunners during the calculation is more work than it was worth.

It was easier just to force the gunner to face north, ensuring that the attachTo command ended up in the same position every time, by creating an invisible H 100 metres north of the mortar, forcing a doWatch then deleting it.

_objTemp = "HeliHEmpty" createVehicle (position _objMortar);
_objTemp setPos [getPos _objMortarGunner select 0, (getPos _objMortarGunner select 1) + 100, 0];
_objMortarGunner doWatch _objTemp;
sleep 5;
deleteVehicle _objTemp;

Edited by bhaz

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
Sign in to follow this  

×