Jump to content
Sign in to follow this  
Heeeere's johnny!

Distance between rifle sight (cursor point) and a man, I'm roughly looking at

Recommended Posts

Hey everyone,

as I was writing some fancy stuff, I was wondering if the following was possible:

I would like to know the distance between my rifle sight (or simply the cursor point) and a man an I'm roughly looking at. There is no scripting command or BIS function to handle this, but I was wondering if there's possibly a workaround to manage this. I want some effect to occur the closer my aim gets to the man.

Does somebody have an idea or do I have to make it rather "inperformant" round 5 corners using X and Y coordinates of the cursorTarget and the man?

Best regards,

waltenberg

Share this post


Link to post
Share on other sites

Do you want the distance on your screen or the distance betwen the point where your rifle is aiming at and the enemy?

Share this post


Link to post
Share on other sites

The distance on the screen would be nice. The distance between the cursorTarget and the enemy is easy to get, but it's not what I want as the cursorTarget could be 100m behind the enemy and that's not the distance I want.

Share this post


Link to post
Share on other sites

Oh ...

So if I did this:

_screenPos = worldToScreen (getPos ((player nearEntities ["Man", 50]) select 0));

I'd get the screen x- and y- coordinates of the center of that man?

Share this post


Link to post
Share on other sites

Well, ... no. What I want is the distance (in pixels, meters, centimeters, whatever) on my screen, just as if I would place a ruler on my screen and measure it.

If I converted the screen's center to world and use the "distance" command between that and the enemy's position, I'd get exactly what I don't want, namely the world distance, which does not say anything about the horizontal distance on my screen.

Yeah, good we understand each other. ^_^

Share this post


Link to post
Share on other sites

If i remeber correctly, [0.5,0.5] would be center of the screen. [1,1] would be the right bottom corner.

It will not be the center of the man, it will be the position of his feets.

If you want to have the center you would need getPosWorld and then use this position with worldToScreen.

Share this post


Link to post
Share on other sites

getPosWorld - good thing to know. I'd probably have done it the pragmatic way by setting the z coordinate + 1. ;)

But thanks, I've learned some interesting and useful new stuff today. I still realize how few SQF commands I actually know though I'm already scripting alot and I always wonder, why I don't find that by searching the BIKI. But anyway, it's always fun to learn something new. :)

Cheers!

waltenberg

Share this post


Link to post
Share on other sites

Well if you do that, it would only be true if the unit is standing.

If it is prone or crouch the z+1 would not be true anymore.

But i'm not 100% sure about the getPosWorld command as it is very new (btw only Dev branch) and i havent tested it much.

You could also try it with visiblePosition.

I suggesst you to browse these lists with all available scripting commands.

Edited by Lappihuan

Share this post


Link to post
Share on other sites

Something like...

_man = ((player nearEntities ["Man", 50]) select 0));
_screenPos = worldToScreen ( _man modelToWorld ( _man selectionPosition "pelvis"));

Would give you the screen position of the units waist no matter what position he is currently in. Then when the new commands come in 1.27 change to modelToWorldVisual for a more presice position of what you are actually seeing.

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
Sign in to follow this  

×