Jump to content
thy_

[SOLVED] Making snipers stay aligned with static target position even at long range

Recommended Posts

I'm having a couple of snipers (same group) reach their spot and then keep watch over a static position (in the image below represented by the lighthouse).

 

n0qPp5B.jpg

 

What we noticed is that the more distant the lighthouse, the more untidy the "distracted" snipers' direction in relation to the position (lighthouse) they were supposed to be watching.

I've given many go to align the group leader's position but the image was my best. Here are some commands that I've already tried: setDirgetDirsetFormDir.

 

But doWatch and lookAt work better and, of course, because of the purpose, I chose to use doWatch.

 

 

initServer.sqf (just for testing):

waitUntil { !isNull grp1 };

private _sniperPos = [3801.55,4266.83,0];

private _wp = grp1 addWaypoint [_sniperPos, 0];

waitUntil {sleep 0.2; ((leader grp1) distance _sniperPos) < 8 };

grp1 setBehaviourStrong "AWARE";
grp1 setSpeedMode "LIMITED";
{ _x setUnitPos "DOWN" } forEach (units grp1);

systemChat format ["Before formationDirection '%1'", formationDirection (leader grp1)];

waitUntil {sleep 3; ((leader grp1) distance _sniperPos) < 1 };

{
	sleep 2;
	//[_x, (_x getDir LIGHTHOUSE)] remoteExec ["setDir"];
	//_x setDir (_x getDir LIGHTHOUSE);
	//[_x, (_x getRelDir LIGHTHOUSE)] remoteExec ["setDir"];
	//_x setDir (_x getRelDir LIGHTHOUSE);
	_x doWatch LIGHTHOUSE;

} forEach (units grp1);

grp1 setFormation "DIAMOND";  // better than LINE 'cause the spotter doesn't get in the sniper's way most of the time.
grp1 setFormDir (getDir (leader grp1));

while { true } do {
	
	["behaviour '%1' / formationDirection '%2' / eyeDirection '%3' / ", behaviour (leader grp1), formationDirection (leader grp1), eyeDirection (leader grp1)] call BIS_fnc_error;
	sleep 2;
};

Demo:

https://drive.google.com/file/d/18QGkzuj53y4LwcPvxpYBASMhiQROB76a/view?usp=sharing

 

 

 

If you got some more to share, please, keep going!

 

 

Share this post


Link to post
Share on other sites

Just making it even more clear: in my all tests, snipers are perfectly looking at the target-area, ok? I am saying alignment = their bodies/weapons.

Share this post


Link to post
Share on other sites

Hi @thy_. A message from the future:

 

You were almost there.

 

Works for single and multiplayer:

[_unit, _unit getDir LIGHTHOUSE] remoteExec ["setDir"];

It's not smooth anim, but works.

 

If you're using setDir for vehicles, pay attention when the ground (right below where the vehicle would stay) is not flat. To avoid explosions or a rocket vehicle flying in the sky, set a new position for the vehicle before change its direction:

_veh setPos [getPos _veh # 0, getPos _veh # 1, (getPos _veh # 2) + 1];  // [x,y,z + 1 meter high from the ground];
[_veh, _veh getDir LIGHTHOUSE] remoteExec ["setDir"];

 

Cheers.

  • Haha 1
  • Confused 1

Share this post


Link to post
Share on other sites

Not exactly

setDir must be BEFORE setPos  (see BIKI notes)

If you are sure _veh is not local, so remoteExec it, but preferable : [_veh, _veh getDir LIGHTHOUSE] remoteExec ["setDir",_veh,_veh];

Share this post


Link to post
Share on other sites
7 hours ago, pierremgi said:

setDir must be BEFORE setPos  (see BIKI notes)

 

Interesting... Even though I never noticed some odd behavior about my goes, I gonna fix it here. Thanks for the head up. 🤗

 

 

q0mCfjL.png

 

 

7 hours ago, pierremgi said:

If you are sure _veh is not local, so remoteExec it

Actually the vehicle is local for the server because is a AI vehicle BUT sometimes, if zeus is playing, they can take that vehicle controll (but 99% that won't happen). 🧐

Share this post


Link to post
Share on other sites
9 hours ago, pierremgi said:

so remoteExec it, but preferable : [_veh, _veh getDir LIGHTHOUSE] remoteExec ["setDir",_veh,_veh];

 

A question, @pierremgi

 

About this ["setDir",_veh,_veh], am I saying that the command effect will be addressed only to _veh? What's happen if we leave just one _veh after the "setDir" instead of two?

 

Just for testing purposes, I did it (["setDir",_veh,_veh]) to a simpleObject, and the simpleObject didn't point to the desired direction. 🤨 But removing the "_veh, _veh", the result was the object pointed in the new direction as expected.

Share this post


Link to post
Share on other sites
16 hours ago, thy_ said:

About this ["setDir",_veh,_veh], am I saying that the command effect will be addressed only to _veh? What's happen if we leave just one _veh after the "setDir" instead of two?

 

The remoteExec has parameters: params remoteExec [order, targets, JIP]  where:

 

- targets can be Object - the order will be executed where the given object is local and that's what you need with setDir, because this command is LA GE. Here you want the command fires on the PC where _veh is. Furthermore, it's usless and counterproductive to fire the code everywhere. Remember the effect is GE (global).

 

- JIP can be also Object, Group or netId - the persistent execution of the remoteExec statement is attached to the given object or group. When the object / group is deleted, the remoteExec statement is automatically removed from the JIP queue.

 

Problem:

I didn't realize the JIP parameter can only be used if the targets parameter is 0 or a negative number.

So I don't know if you can use it with an object (_veh as target), without issue. Perhaps it's just useless, perhaps it's wrong....    You can test ["setDir",_veh] only.

 

Remark:

I you spawn _veh on server and apply the code before any player takes the ownership of the vehicle (perhaps never), you can run it right after spawning, without remote execution (what for?)

 

 

Your question is all over the place:

 

17 hours ago, thy_ said:

Just for testing purposes, I did it (["setDir",_veh,_veh]) to a simpleObject, and the simpleObject didn't point to the desired direction.  But removing the "_veh, _veh", the result was the object pointed in the new direction as expected.

 

So, if simple object is on server (I guess it is), apply the code on server and that's all. Same if spawned from client:  why remoteExec when you are already local?

See also performance. (not so efficient for houses)

 

 

 

  • Thanks 1

Share this post


Link to post
Share on other sites
6 hours ago, pierremgi said:

So, if simple object is on server (I guess it is), apply the code on server and that's all. Same if spawned from client:  why remoteExec when you are already local?

 

 

After your explanation, it became so obvious. Your enlightening answer was greatly appreciated.

 

Basically: use remoteExec only if the LA command will be executed by an object that could have a new owner (e.g. when a vehicle spawned through a server code, and a player ramps in, transferring automatically that vehicle ownership to that specific player machine). Otherwise, regardless if the code is on the server or on the client (player), if the ownership will be always on the same machine, no reason to use removeExec "to transfer a command" for the new owner. More: if we are talking about a simpleObject, there is no reason to apply removeExec to something (in 99,99%) that won't leave its current ownership to another machine ('cause simpleObjects aren't interactive). 

 

😅

 

So, applying what I've learned here:

 

For those AI units (snipers):

_unit setDir (_unit getDir LIGHTHOUSE);
// in this case, units wouldn't have issues with collision with rough terrains, so setPosATL not needed.

But if the setDir must be applied to a vehicle (perhaps) will be taken by some player for example:

[_veh, _veh getDir LIGHTHOUSE] remoteExec ["setDir", _veh];
_veh setPos [getPos _veh # 0, getPos _veh # 1, (getPos _veh # 2) + 1];  // [x,y,z + 1 meter high from the ground] to avoid rough terrain collisions;

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

×