Jump to content

scottb613

Get the position of what the player is aiming at?

Recommended Posts

Hi Folks,

 

I've been trying to capture the position the player is aiming at - using cursorTarget and screenToWorld - I think I need to be using lineIntersectsSurfaces. 

 

No joy. 

 

This seems like a task in common use in many scripts. Best way to achieve this?

 

This fails.

// Get the position the player is pointing at
_startPos = eyePos player;
_endPos = _startPos vectorAdd (vectorMultiply (vectorDir player, 1000));
_intersect = lineIntersectsSurfaces [_startPos, _endPos, player, objNull, true, 1, "GEOM", "NONE"];
_pointedPos = _intersect select 0 select 0;

 

Thanks.

 

Regards,
Scott

Share this post


Link to post
Share on other sites

Already in MGI advanced module (Terrain and map interactive module) See doc.

 

The code (similar) I'm using:

addMissionEventHandler ["Map", {
    params ["_open"];
    deleteMarkerLocal "MarkerTgt";
    if (cameraView == "gunner" && _open) then {
        private _ins = lineIntersectsSurfaces [AGLToASL positionCameraToWorld [0,0,0],AGLToASL positionCameraToWorld [0,0,5000],player,objNull,true,1,"VIEW","NONE"];
        private _cursor_distance = if (count _ins > 0) then [{(_ins select 0 select 0) vectorDistance (eyepos player)},{5000}];
        private _mk = createMarkerLocal ["MarkerTgt",position player];
        _mk setMarkerTypeLocal "mil_destroy";
        _mk setMarkerSizeLocal [(markersize "MarkerTgt" select 0)/1.5,(markersize "MarkerTgt" select 1)/1.5];
        _mk setMarkerPosLocal (positionCameraToWorld [0,0, _cursor_distance]);
    };
}];

Opening the map when player is aiming (so as gunner view even for infantry (scope)), show a cross marker on map.
NOTE: This marker is local. If a player wants to share the position, he must create a marker on map.

  • Like 3

Share this post


Link to post
Share on other sites

Hi Pierre,

 

Working on a little script to easily order my associated APC to move around - without opening the map - when in close combat with my squad.

 

I did get it kind of working but my waypoints were being created like 100 meters further out than I was actually aiming - on the correct bearing though - not sure why.

 

You nailed it - works perfectly - adapted same - thanks so much!

😊

 

You would think that BIS would have made this a simple command.

 

Not done yet.

// Ensure MyRide is defined
if (isNil "MyRide") exitWith {hint "TRANSPORT not defined";};

// Get the vehicle from the global variable
_vehicle = missionNamespace getVariable "MyRide";

// Ensure the vehicle is valid
if (isNull _vehicle) exitWith {hint "TRANSPORT not valid vehicle";};

// Clear all old waypoints using a while loop
_group = group _vehicle;
while {(count (waypoints _group)) > 0} do {
    deleteWaypoint ((waypoints _group) select 0);
};

// Get the position the player is pointing at using camera position and AGLToASL
_startPos = AGLToASL positionCameraToWorld [0, 0, 0];
_endPos = AGLToASL positionCameraToWorld [0, 0, 5000];

// Find intersections along the line from _startPos to _endPos
_intersect = lineIntersectsSurfaces [_startPos, _endPos, player, objNull, true, 1, "VIEW", "NONE"];

// Calculate the distance to the first intersection
_cursor_distance = if (count _intersect > 0) then {
    (_intersect select 0 select 0) vectorDistance (eyePos player)
} else {
    5000
};

// Calculate the waypoint position based on the camera's aiming point
_pointedPos = positionCameraToWorld [0, 0, _cursor_distance];

hint "TRANSPORT on the way";
sleep 5;

// Delete all existing markers
{
    deleteMarker _x;
} forEach allMapMarkers;

// Create a marker at the position the player is aiming at (_pointedPos)
_markerAimedName = createMarker ["AimedPositionMarker", _pointedPos];
_markerAimedName setMarkerType "hd_dot";  
_markerAimedName setMarkerColor "ColorBlue";  
_markerAimedName setMarkerText "Aimed Position";

// Create a new waypoint at the pointed position
_newWaypoint = _group addWaypoint [_pointedPos, 0];
_newWaypoint setWaypointType "MOVE";

// Set the vehicle's speed
_vehicle forceSpeed -1;  // Reset any forced speed
_vehicle limitSpeed 45;  // Set speed mode to limited (typically around 45 km/h)

// Move to the new waypoint
_group setCurrentWaypoint _newWaypoint;

 

Regards,
Scott

  • Like 1

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

×