Jump to content
Sign in to follow this  
engima

Reset armor gunner's "lookAt"

Recommended Posts

Hi

I have a question about armor gunner and the lookAt command.

What I want:

I want a tank to stand still for a while just looking around and then continue with waypoints.

How i do it:

I script the tank's gunner to look at (using script command "lookAt") some positions around the tank. When it's time for the tank to move on the gunner is scripted to look at a position in direction "getDir tank". The tower turns in a forward direction and the tank moves on. Works almost fine.

Problem:

The gunner keeps looking at the position i made him, so when the tank turns, the gun will not be pointed in a safe forward direction. When gun is pointed forward i use script command "_gunner lookAt objNull", but it doesn't help. Somehow I would need a way to *reset* the gunner so that the gun stays in a forward direction (with reference to the vehicle).

Can anyone see what I have missed?

Share this post


Link to post
Share on other sites

I don't think there is a command, it's quite annoying when a tank is going up a road his gun is swinging right across it.

I have used this to improve the situation place an object on the map directly in front of the tank and place this in it's init

name the item obj1

obj1 hideobject true;obj1 attachto [tank];

The when you want to make the gun look forward setup a trigger and place this in on act.

on act

fix_gun=true ;null=[] spawn {while {alive tank and fix_gun} do {sleep 0.5;gunner tank dowatch obj1}}

When you want it to return to normal you will need to issue fix_gun=false in a trigger or waypoint

It's not perfect but better than nothing.

Share this post


Link to post
Share on other sites

Here's a little script so when the tank is moving and no enemies are present then the turret faces forward:

_tank = vehicle player;

while {_tank != player and _tank isKindOf "TANK"} do
{
if (speed _tank > 0 and objNull != _tank findNearestEnemy _tank) then
{
	sleep 0.5;
	gunner _tank dowatch (_tank modeltoworld [0, 100, 0]);
};
};

Whenever you stop, you can tell the gunner to scan horizon or whatever and when the tank moves off, then the gunner will look to a vector 100m in front of him. If enemies are detected, they will over-ride this behaviour.

Just activate it in a trigger or in mission init (if you need to get out of the tank and back in then you'll need to do a little extra work on the script).

Share this post


Link to post
Share on other sites

Amendment!

The code was bad. Although it works; if the tank is stopped, or if there are bad guys around, the script will check every frame (not good for performance). If you move the sleep 0.5; out of the second scope and into the first, the script will pause for half a second irrespective of the conditions:

private ["_tank"];

_tank = vehicle player;

while {_tank isKindOf "TANK"} do
{
   if (speed _tank > 0 and objNull != _tank findNearestEnemy _tank) then
   {
       gunner _tank dowatch (_tank modeltoworld [0, 100, 0]);
   };
   sleep 0.5;
};

Got rid of the unnecessary condition as well.

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  

×