Page MenuHomeFeedback Tracker

screenToWorld, eyeDirection do not return useful y-axis (height) components
Reviewed, NormalPublic

Description

When trying to determine the vector along which either the player, the player character or a non-player unit is looking we run into a ahow-stopping problem. Namely, although we can easily find the corresponding x,z world co-ordinates, there is no way to return an useable y world co-ordinate for height, and, consequently, we have no way to reliably determine the POV pitch angle.

Observation of the y values returned by screenToWorld indicates that provided the position returned by the command is located upon the terrain itself everything is in order. When sampling any points above the landscape, however, screenToWorld returns values which cannot be used to calculate an accurate 3D POV vector. EyeDirection, OTOH, simply returns an approximately horizontal vector at all times (ie., 2D vector). Incidentally, vectorDir also does not work, although this is by design since it is meant to return the vector direction of the entire object model rather than head or gaze vector.

Currently, the best proxy for determining gaze pitch angle is weaponDirection, but this is problematic as a character has to be both armed and have a weapon raised in order for this command to serve our purposes. Perhaps something could be kludged together using selectionPosition on a character's head, but this would be a cumbersome workaround at best.

Would it be possible for both screenToWorld and eyeDirection to return y values that could then be used to compute an accurate 3D POV vector? Note, that screenToworld is not necessarily equivalent to eyeDirection as the former indicates where the player's camera is looking and the latter indicates where an in-game character model is looking. {F18378}

Details

Legacy ID
3244497691
Severity
Minor
Resolution
Open
Reproducibility
Always
Category
Scripting
Steps To Reproduce
  1. Start repro mission.
  2. Move the player's view around and note the pitch angles output displayed in the hint (note: hint loop uses "sleep 5" for easier realtime visual comparison).

Event Timeline

MakeLoveNotWar edited Additional Information. (Show Details)
MakeLoveNotWar set Category to Scripting.
MakeLoveNotWar set Reproducibility to Always.
MakeLoveNotWar set Severity to Minor.
MakeLoveNotWar set Resolution to Open.
MakeLoveNotWar set Legacy ID to 3244497691.May 7 2016, 1:04 PM

NB: For the pitch angles displayed by the hint in the repro mission, 0 == straight up, 90 == horizontal, 180 == straight down.

I've noticed that if you have a weapon eyeDirection vector is tied to the weaponDirection, unless you turn on freelook, at which point it becomes relative to the weaponDirection.

It would be nice to be able to get the current camera vector.

It is a mess. eyeDirection is not tied to the weapon direction. Weapondirection when lowered is different to weapondirection when aimed yet it makes no difference for eyeDirection. eyeDirection however shows correct elevation vector only when in freelook or with no weapon.

sms added a comment.Aug 9 2013, 7:26 PM

Here is my 2 cents:

http://www.youtube.com/watch?v=CwJWXcGDgK4

_dummy = [] spawn
{

    _sign = "Land_Sign_Mines_F" createVehicle [0, 0, 0]; 
    while {true} do 
    {
        _ep = eyePos player; 

        _ed = [eyeDirection player, 10] call BIS_fnc_vectorMultiply; 
        _s = [_ep, _ed] call BIS_fnc_vectorAdd; 

        _sign setPos _s;  

        sleep 0.01;
    };

};

Problem is that eyeDirection returns vector relative to player's body and NOT the world. Thing is that when you look up and down with no weapon your body also leans forward and backwards but when you do have a weapon it doesn't so vector is always parallel to your body which is perpendicular to ground\sea level.

Here is my test code:

true spawn {test = false; sleep 1; test = true; while{test} do {
objs = [];
_pos = eyePos player;
_dir = eyeDirection player;
for "_i" from 1 to 10 do {

		_pos = eyePos player;
		for "_j" from 0 to 2 do {
			_pos set [_j, (_pos select _j) + (_dir select _j) * 0.5 * _i];
		};
		_o = createVehicle ["Sign_Sphere10cm_F", ASLtoATL(_pos), [], 0, "CAN_COLLIDE"];
		_o setPosASL _pos;
		objs set [count objs, _o];

};
sleep 0.1;
{deleteVehicle _x} forEach objs;
};};

Get yourself a weapon, aim as far down as possible and then start to slowly rotate your head around to see that eyeDirection returns vector relative to your body, not the world.

Here is update and much better code to see the problem:

onEachFrame {
objs = [];
_pos = eyePos player;
_dir = eyeDirection player;
for "_i" from 1 to 10 do {

		 _pos = eyePos player;
		 for "_j" from 0 to 2 do {
			 _pos set [_j, (_pos select _j) + (_dir select _j) * 0.5 * _i];
		 };
		 _o = createVehicle ["Sign_Sphere10cm_F", ASLtoATL(_pos), [], 0, "CAN_COLLIDE"];
		 _o setPosASL _pos;
		 objs set [count objs, _o];

};
{deleteVehicle _x} forEach objs;
};

If devs will ever pay attention to this ticket, I will make repro mission with full steps.