Jump to content

weaponDirection vs animationPhase/animationSourcePhase

Recommended Posts

Hi there,


It would be amazing if somebody would be able to clarify this: In the biki for weaponDirection, it's stated that animationPhase and animationSourcePhase can be used to return the radians for turret direction (or in my case elevation) when using vehicles. But it turns out they are not the same:


Testing with gunner position:

(_vehicle weapondirection currentweapon vehicle player) select 2

>> returns -0.0989731 (example)

_vehicle animationPhase "MainGun"


_vehicle animationSourcePhase "MainGun"

>> in the same example, they both return -0.052165 which is a big shift

Correspondingly using deg(x) also yields dramatically different results


The weaponDirection example works perfectly for what I'm trying to achieve, but that's only an option for the gunner and the results for the commander turret are totally off unfortunately. 


Hope the oracle can help! Thank you :)


Share this post

Link to post
Share on other sites

You didn’t specify what exactly that you need and yes they return different results, one returns z offset and one the actual angle of elevation 

Share this post

Link to post
Share on other sites

Thanks for your reply @killzone_kid ! And apologies, I'm in a bit over my head and don't have the terminology straight exactly.


In short, what I need is the equivalent of weapondirection (specifically the z value)  for the commander's turret, so the actual angle of elevation. 


Longer version  (maybe the script explains it better) : I'm trying to find lineIntersectsSurfaces between the players camera and where the player is 'looking', so I can snap an object to it.

I use ATLtoASL (screenToWorld [0.5,0.5]) as the target position. The problem with that is that it always returns a z-value of 0, so it only works if you have a terrain-intersect between ATLtoASL (positionCameraToWorld [0,0,0]) and ATLtoASL (screenToWorld [0.5,0.5]), or if the position you look is below your cam's position. If you 'look' above the 'horizon' for the lack of a better word, screenToWorld will return a position on ground level, at a distance that seems connected to viewDistance. So if you are say in the VR-map, which is flat, then place a HQ-Tower and point your look at it's top floor, you will not get the intersect between your cam's position and the building using lineintersects.

For this reason I am creating a triangle, using the camera's elevation angle. It works well enough for me when using weaponDirection or cameraViewDirection's z-values, but I need an alternative for when the player is commander of a vehicle and using the "GUNNER" camera mode.


Script example of what I am doing: I need to get this working for when the player is commander of the vehicle and using 'GUNNER' cameraview.

//-- get base information, point A and B
_vehicle = vehicle player;
_refPos1 = ATLtoASL (positionCameraToWorld [0,0,0]);
_unitHeightASL = _refPos1 select 2;
_refPos2 = (screentoworld [0.5,0.5]);

_angle = (_vehicle weapondirection currentweapon _vehicle) select 2; 
//-- simplified example. I have a function to return angle depending on circumstances, it can also return: (getCameraViewDirection player) select 2
//-- when the player is in commander turret and "GUNNER" view, I used (_vehicle animationPhase "obsGun") >> I need an alternative

//-- create a triangle to get point C    
_refDist = _refPos1 distance2d _refpos2;
_refHeight = _unitHeightASL + (_refDist * (tan (deg _angle)));
_refPos2 set [2,_refHeight];

_interSectList = lineIntersectsSurfaces [_refPos1,_refPos2, player, vehicle player, true, 1, "GEOM", "NONE", true];
_return = ((_interSectList select 0) select 0);
//-- _indicator setPosASL _return




Share this post

Link to post
Share on other sites

So basically you want to calculate second point for lineIntersectsSurfaces? If you take as origin positionCameraToWorld then the example on lineIntersectsSurfaces page shows exactly how you get end point. If you however want weapon direction, you first need to take origin that is base of the barrel and not player camera and extend it in direction of the barrel, just like it is shown in example on https://community.bistudio.com/wiki/weaponDirection Unfortunately even after your lengthy description it is not clear what you are trying to achieve or you are trying to go wrong way about it.


PS screenToWorld is most definitely not the right approach

Share this post

Link to post
Share on other sites

Thanks @killzone_kid and sorry - I had a wrong understanding of positionCameraToWorld as far as the second point is concerned, I missed the example from the biki because I thought it checked 1000m above the camera, not including the direction. Makes sense looking from it that way that it would not be clear what the hell I was trying to do in the first place! Thank you, although I feel a bit stupid now this definitely solved my problem. 


One last question remains: is there a way to get lineIntersectsSurfaces between the position of the commander turret and the position it is pointing at? This would be useful for me when the player is commander and in "Internal" view.

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