Jump to content
Sign in to follow this  
Coucoul38

How to make a turret rotate with a script.

Recommended Posts

Hi, I'm changing the player's vehicle with a script, and I want the turret of the new vehicle to face the same way as the old one did.
Before changing the vehicle, I'm getting the old turret's aiming position with this:

_turretDirection = eyePos vehicle _x;

And to make the new turret rotate I tried this :

_veh unitTurret(_x) lookAt _turretDirection;

and this:

_x lookAt _turretDirection;

but it doesn't work.

Share this post


Link to post
Share on other sites
14 hours ago, Coucoul38 said:

I want the turret of the new vehicle to face the same way as the old one did.

This can be tricky to get right...

 

lookAt only works on AI so you would need to replace the player with an AI to turn the turret, same with doWatch which I prefer. Neither of them is foolproof though. Sometimes the AI will just refuse to turn it, or go back to "neutral" directly after finishing the turn.

 

Turrets can be turned and elevated through script by animating the correct part. Main problem with this approach is that the names and parameters of the anim will likely vary between vehicles, especially if you're using modded content. Afaik there's no onesize-fits-all solution for this.

 

There's also different vehicle sizes, turret layouts and traversal limits to consider. When the new vehicle is created you would have to guarantee that the aim direction aligns perfectly with whatever the player is looking at or the experience may be quite jarring.

 

My recommendation: Just fade to black while you change vehicles.

 

Share this post


Link to post
Share on other sites

Well I tried to do it, but it is not instantaneous, and most importantly the eyePos function actually returns the position of the optic ?

So I need to find a function that returns the coordinates where the player is looking at.

Either that or find a way to rotate the turret so that it aligns with a vector that I can get using this:

eyeDirection vehicle _x


 

Share this post


Link to post
Share on other sites
14 hours ago, Coucoul38 said:

So I need to find a function that returns the coordinates where the player is looking at.

screenToWorld [0.5, 0.5]

  • Thanks 1

Share this post


Link to post
Share on other sites
On 5/4/2023 at 11:07 AM, mrcurry said:

screenToWorld [0.5, 0.5]

Thanks, this works perfectly.
Do you know if it's possible to speed up the turret traverse so that it's almost instantaneous?

Share this post


Link to post
Share on other sites

I just lost my HDD with arma on it so can't check but here's a couple of options:

 

setAnimSpeedCoef allows you to change animation speed for units but don't think it works for vehicles. If it does you could speed up the animation that way.

 

setTurretLimits allows you to limit the the range of turrets, if you get the pitch and yaw to target you could limit the turret to the desired direction and then reset the limits when the target is reached. In theory the view should "snap" to stay within the limits, not sure if it'd work but worth a shot.

Share this post


Link to post
Share on other sites

I used this for arma2  worked great however never used it for arma3 still may work or you can tweak the commands.

 

 

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  

×