Page MenuHomeFeedback Tracker

Command setFormDir is wrong by a magnitude of 30
Closed, ResolvedPublic

Description

I am working on a script and I believe I have found a bug with the command 'setFormDir'. It happens pretty randomly, I'm not sure what could be causing this under the hood, but whenever it's wrong, it's always wrong by 30 degrees.

Details

Legacy ID
1178777121
Severity
None
Resolution
No Bug
Reproducibility
Sometimes
Category
Scripting
Steps To Reproduce
  1. Place down your player and a friendly trooper (just so he won't shoot you).
  2. Give your friendly unit a name, any name works fine.
  3. Copy & paste this code into his initialization field:

this addAction ["Turn Around",
{
_dir = (direction (_this select 0)) - 180;
(_this select 0) setFormDir _dir;
}, [], 6, false];

  1. Preview your mission and paste this into the debug console and run it:

UNIT_NAME spawn
{
while {true} do

		{
			hintSilent str (direction _this);
		};

};

  1. Go up to the guy and use the action a bunch of times. I would say the bug happens about 10-20% of the time, so it's pretty low, but definitely there.
Additional Information

The 4th step in the reproduction steps is not really required. Visually, the units obviously sometimes do not turn the amount they're supposed to. After adding that spawn, I saw that it is always wrong by 30 degrees, if it is.

Unrelated, but I don't think it's a big enough problem to warrant a separate ticket, I just haven't found the proper place to throw this out there...the tooltip for the 'Product Version' on the feedback tracker itself is incorrect. It says that you can find the version in the top-right at the main menu, but the version is actually on the bottom-right of the main menu. At least for me.

Event Timeline

DreadedEntity edited Additional Information. (Show Details)
DreadedEntity set Category to Scripting.
DreadedEntity set Reproducibility to Sometimes.
DreadedEntity set Severity to None.
DreadedEntity set Resolution to No Bug.
DreadedEntity set Legacy ID to 1178777121.May 7 2016, 7:52 PM

Can confirm this. The difference is EXACTLY 30 degrees.

Place a AI unit call it bob. Run this

60 spawn {bob setformdir _this; sleep 1; hint str [_this, direction bob]};

result is [60, 30]

180 spawn {bob setformdir _this; sleep 1; hint str [_this, direction bob]};

result is [180, 150]

240 spawn {bob setformdir _this; sleep 1; hint str [_this, direction bob]};

result is [240, 210]

Direction of the unit after setformdir command seems to follow this logic:

if desired bearing is more than 30 degrees from original bearing then resulting turn would be desired bearing - or + 30 depending which way unit is turning.

if desired bearing is less than 30 degrees from original bearing then unit might not turn at all as resulting bearing difference will be less then 30

Very weird behaviour.

Perhaps this is the reason why AI don't look where you tell them when using the watch/cover command, or whatever it is, in the commanding menu.

I agree, KK. The worst part of it is that you can use setDir to turn the units, but it doesn't look fluid at all, and the unit will attempt to turn back to his original azimuth for some reason. So having the units not turn all the way is a big problem. I also saw that if the new bearing is within 30 degrees of the original, the unit just won't even turn at all, I think it has a 100% reproduction rate.

I think somebody wasn't paying enough attention in trigonometry class when they coded this command :P

chose added a subscriber: chose.May 7 2016, 7:52 PM
chose added a comment.Dec 4 2014, 9:50 AM

If you apply the command to a group of units rather than an individual, you'll see that their formation bearing is correct. Different formations have various directional offsets for their members and using only setFormDir to change the direction of a single unit is not advised.

In order to make a unit stay in the desired direction, use setFormDir and then setDir as well.

@chose

That's a good workaround, but I'm not really satisfied with it. I think for just a single unit, the formation direction should be his absolute direction.

Anyway, I'm using this workaround with usually a high degree of success.
_this addAction ["Speak To",
{
_vd = (getPosASL (_this select 1)) vectorDiff (getPosASL (_this select 0));
_dir = (_vd select 0) atan2 (_vd select 1);
if (_dir < 0) then {_dir = 360 + _dir};
hint str ((direction (_this select 0)) - _dir);
if (((direction (_this select 0)) - _dir) > 0) then
{

		(_this select 0) setFormDir (_dir - 30);

}else
{

		(_this select 0) setFormDir (_dir + 30);

};
}, [], 6, false];
This also solves the problem of units not turning AT ALL if the new direction is less than 30 degrees by offsetting the new direction by 30 degrees.

Resolving as no bug according to dev note.