Jump to content
PheNux Cam

Direction Facing Script Help

Recommended Posts

I'm working on a little script for my milsim unit and I'm creating a formations training board.

 

1_zpseklaojae.jpg

This is my little spawnboard I created and I have a script that is going to spawn some ai in different formations, such as a wedge, line, column etc. Right now you are viewing the line. My issue is that when I spawn these guys in with the script I cannot get them to face my direction, they just default back to facing the north direction no matter what. I've been stuck on it for about 6 hours and tried everything, dowatch, lookat, setdir, setformdir, I even created another empty marker as a direction for them to watch towards if possible but nothing works.

 

2_zpsgtegtxrs.png

Here you can see a map view of what I have setup, the empty markers with the ai I've spawned, the spawnboard, and another empty marker as a potential direction to look at.

 

4_zpsov932nkg.jpg

 

Lastly, here is the code I'm working with. I have only been scripting for about a week now so I am still new to this all but i've managed to do this all from tutorials and constant study of the wiki though things are still confusing, please help thanks <3.

Share this post


Link to post
Share on other sites

Yeah, I have been playing around with that but I feel that I may not be entering it properly. So far I have it this way

 

[getMarkerPos "man1" setFormDir 270];

 

I have to use getmarkerpos man1 since it is my marker to spawn the man so it has to be my object. Then when I try the board I get an error.

 

1_zpsfsltqvuw.jpg

I still have difficulty comprehending what I am doing wrong but somehow I feel it might be simple.. like an error in syntax or something, can you give me an example to fix it properly?

Share this post


Link to post
Share on other sites

This command is applicable to unit/group only, but you trying to apply it to coordinate array. Why you never read description of the commands before using them?

  • Like 1

Share this post


Link to post
Share on other sites

I did read over it like 100 times and tried to comprehend, but that is what happens when you are days new to something, I'm a bit slow stupid. Therefore, what would be the proper way to fix this then??

Share this post


Link to post
Share on other sites

getMarkerPos "man1" is returning a position array. So it essentially is doing this:

[_x,_y,_z] setFormDir 270

 

As Serena said, it needs to be a unit, not a position. 

 

_unit setFormDir 270;

Or

{_x setFormDir 270} forEach (units _group);

 

It'd be worth reading up on forEach and units in the command reference to learn more about them. 

 

Sorry, to add to this, i believe a further setDir is then needed, but check the link killzone kid posted, it should be in there. 

Share this post


Link to post
Share on other sites
5 minutes ago, beno_83au said:

getMarkerPos "man1" is returning a position array. So it essentially is doing this:

[_x,_y,_z] setFormDir 270

 

As Serena said, it needs to be a unit, not a position. 

 

_unit setFormDir 270;

Or

{_x setFormDir 270} forEach (units _group);

 

It'd be worth reading up on forEach and units in the command reference to learn more about them. 

 

Sorry, to add to this, i believe a further setDir is then needed, but check the link killzone kid posted, it should be in there. 

Thanks I'll work on it

Share this post


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

Therefore, what would be the proper way to fix this then??

Something like:

// spawn group (abstract line, replace with your own)
private _group = [...] call BIS_fnc_spawnGroup;

// order group to face 45'
_group setFormDir 45;

// rotate each unit of group
{_x setDir 45} forEach (units _group);

* fixed

Share this post


Link to post
Share on other sites
Just now, serena said:

private _group = [...] call BIS_fnc_spawnGroup;

 

I tried this but it doesn't work, it gives me error:

 

Quote

19:28:17 Error in expression <private _group = [...] call BIS_fnc_spawnGroup;>
19:28:17   Error position: <...] call BIS_fnc_spawnGroup;>
19:28:17   Error Invalid number in expression

 

Share this post


Link to post
Share on other sites

PheNux Cam, first line of code in my sample is abstract, it is introduced only to show how to "_group" variable initialized.

 

private _group = [...] call BIS_fnc_spawnGroup;
//               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ abstract part, replace with your own code

 

Share this post


Link to post
Share on other sites
35 minutes ago, killzone_kid said:

I tried this but it doesn't work, it gives me error:

Nice error reporting. You just need to replace three dots with actual arguments from here and then everything will work fine :)

Share this post


Link to post
Share on other sites
28 minutes ago, serena said:

PheNux Cam, first line of code in my sample is abstract, it is introduced only to show how to "_group" variable initialized.

 


private _group = [...] call BIS_fnc_spawnGroup;
//               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ abstract part, replace with your own code

 

Thanks for helping :) <3

Share this post


Link to post
Share on other sites
27 minutes ago, PheNux Cam said:

Thanks for helping :) <3

//  fixed last line
{_x setDir 45} forEach (units _group);

 

Share this post


Link to post
Share on other sites

Perhaps I'm remembering incorrectly, but I thought all members of the group would go back to facing the direction of the group leader, even after individual units were given setdir commands?

Share this post


Link to post
Share on other sites

Tankbuster, you're right. Individual unit rotating is ambigous in most cases. Just tested this code, all works fine:

// init.sqf
player addAction ["Spawn Team", {
	mygroup = [player modelToWorld [0,25,0], WEST, 5] call BIS_fnc_spawnGroup;
	player removeAction (_this select 2);
	player addAction ["Set Formation North", {mygroup setFormDir 0}];
	player addAction ["Set Formation East", {mygroup setFormDir 90}];
	player addAction ["Set Formation South", {mygroup setFormDir 180}];
	player addAction ["Set Formation West", {mygroup setFormDir 270}];	
}];

Sample mission: link

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

×