OFPEC Forum

Editors Depot - Mission Editing and Scripting => Arma2 - Editing/Scripting General => Topic started by: alimag on 03 Sep 2009, 17:37:25

Title: Where is my weapon pointing?
Post by: alimag on 03 Sep 2009, 17:37:25
Hi,

Is there a way to calculate where my weapon (the player) is pointing.
I mean, if I had to fire a bullet where would be the point of impact.

Or is there an Arma II built in function that can do the job?

I need it to know at what object or what position on the ground the player's weapon is pointing.

Thanks in advance

Cheers
Title: Re: Where is my weapon pointing?
Post by: JamesF1 on 03 Sep 2009, 17:48:52
This should really have gone in Arma2 - Editing/Scripting General (http://www.ofpec.com/forum/index.php?board=111.0).  There are a number of ways of doing it, but I can't remember who's made scripts to achieve it, off-hand - a quick search should turn something up (presuming you haven't already).  Not sure if Spooner's view vector stuff (or something similar) will do the job.
Title: Re: Where is my weapon pointing?
Post by: alimag on 03 Sep 2009, 19:01:55
Hi,

Sorry for posting at the wrong place.

I've tried searching but no result. I probably does not use the right keyword(s).

Thanks for answering anyway.

Cheers
Title: Re: Where is my weapon pointing?
Post by: Pirin on 04 Sep 2009, 04:56:28
http://community.bistudio.com/wiki/cursorTarget (http://community.bistudio.com/wiki/cursorTarget) and http://community.bistudio.com/wiki/screenToWorld (http://community.bistudio.com/wiki/screenToWorld) might be helpful?
Title: Re: Where is my weapon pointing?
Post by: alimag on 04 Sep 2009, 18:58:03
Hi,

Thanks Pirin.

screenToWorld seems to be something that would work with a dialog. Its parameter looks like the X and Y position of a dialog element. I'm not sure yet what can be done with it.

cursorTarget seems much more interesting for what I want to do. Its a shame it does not return all the objects, including road and other builtin island objects, but just people, vehicles and big buildings.
But it's still is a start and certainly a step in the right direction. I'll see what I can do with it.

Thanks again

Cheers

EDIT

I just tried both and there is something I did not realize right away is that the player's weapon is always pointing to the center of the screen ([0.5, 0.5]). So it makes screenToWorld exactly what I needed. Fantastic.

You're a lifesaver Pirin  :good:

Cheers
Title: Re: Where is my weapon pointing?
Post by: Mandoble on 04 Sep 2009, 20:03:56
That is technically wrong, player's weapon is pointing at center of screen ONLY if player eyes are pointing where the weapon is pointing. Also screenToWorld will not give you correct info when you are not looking to ground positions and inside view distance. Might be the command you are looking for is weaponDirection (http://www.ofpec.com/COMREF/index.php?action=details&id=816&game=All), but it requires you pass it a weapon name, so then you need to find out which weapon is handling the player. I did something (http://www.ofpec.com/ed_depot/index.php?action=details&id=435&game=ArmA) for ArmA1 that might be still working for ArmA2 to find out the handled weapon.