gossamersolid 155 Posted March 28, 2015 I've searched around for an answer and haven't been able to find anything definitive. I'm attempting to grab the position of what the player's crosshair is aiming at. This works fine and dandy in some cases, but it fails quite often due to cursorTarget returning objNull if the player does not "know about" the cursorTarget object. I've seen people saying to keep revealing all objects within the view distance, but that's quite a dirty workaround and frankly, I feel like it will negatively affect performance by a noticeable amount. Has anybody managed to get a solution for this issue? Share this post Link to post Share on other sites
cosmic10r 2331 Posted March 28, 2015 Give this a whirl... we use it in samo... the issue with cursor target as you know is it has to be an object... Screen to world is coordinate based https://community.bistudio.com/wiki/screenToWorld Share this post Link to post Share on other sites
gossamersolid 155 Posted March 28, 2015 Hmmm, I've tried this command before. The problem I had with it, is that it relies on world position (as you said), which means if I'm level with an object (and I don't know about this object), then I get the position of the terrain potentially 1km or so away. I've also tried this command: https://community.bistudio.com/wiki/lineIntersectsObjs but it wasn't reliably returning the object I was looking at either. Share this post Link to post Share on other sites
mikey74 188 Posted March 28, 2015 (edited) have you tired cursorTarget or screen to world but get object by using _cursor_obj = getPos cursorTarget nearEntities [["CAManBase","LandVehicle"], 0]; or _cursor_obj = nearestObject getPos cursorTarget; or _cursor_obj = nearestObjects [getPos cursorTarget, [], 0] The last one is probably what I'd use, and I'd probably go screen to world over cursorTarget depending on what your trying to grab. In other words I'd probably do something like this: _AIMPosA = screenToWorld [0.5,0.5]; //_xpos = _AIMPosA select 0; //_ypos = _AIMPosA select 1; //_AIMPosB = [(_xpos),( _ypos),0]; _cursor_obj = nearestObjects [_AIMPosA, [], 0]; if it gives you array has 2 elements error then un // out the center 3 and change _AIMPosA to _AIMPosB like this : _AIMPosA = screenToWorld [0.5,0.5]; _xpos = _AIMPosA select 0; _ypos = _AIMPosA select 1; _AIMPosB = [(_xpos),( _ypos),0]; _cursor_obj = nearestObjects [_AIMPosB, [], 0]; Edited March 28, 2015 by Mikey74 Share this post Link to post Share on other sites
gossamersolid 155 Posted March 28, 2015 Just from some quick tests, the same problem occurs as described in my above post. If cursorTarget returns objNull (which happens usually at distances), then you must rely on the position provided by screenToWorld. screenToWorld doesn't intersect with objects. This means unless I'm looking down towards the ground where the unit is, I will not get the unit, I will get a position at some terrain that could be far away behind the unit. It works fine if I'm looking down, but if you're going uphill and you don't "knowsAbout" the target, you won't get the correct position. Share this post Link to post Share on other sites
Guest Posted March 28, 2015 I really don't know if it may help, but In Vcom AI, there is a HitNear script the author uses that seems to revolve around the use of CursorTarget along with a lot of other code mixed in to track bullets fired nearby enemy units to get them to react. Again I don't know if it helps or not, but here is the link main page for the mod: VcomAI Main Page Share this post Link to post Share on other sites