I am trying to detect where the cross-hair is pointing

Post » Sun Aug 08, 2010 1:34 pm

I am trying to detect where the cross-hair is pointing for Zombies that can only be killed by a head shot.
But my trig is very very weak (I cannot visualizes the angles/numbers in my mind the same way I can in geometry)
and I am not sure about one part of the script.

I think that

set Posz to ( Posz - ( player.getpos z * MyScale ) )

is not the right way to compensate for the players scale. But I am not sure how else to do it.
I do not need this kind of adjustment for the zombies as they will always be the same scale.


Scriptname aadpHeadShotRef targetFloat PoszFloat angxRef raceFloat Myscalebegin gamemode;;;This is for testing onlyset target to GetCrosshairRefif target != 0 if IsFormValid target != 1   set target to 0    elseif target.getdisabled == 1 || target.getdead == 1 || target.isactor == 0    set target to 0 endifendifif target != 0  set Posz to target.getpos z  set race to player.getrace  set Myscale to getracescale race  set Posz to ( Posz - ( player.getpos z * MyScale ) )  set Posz to Posz + 95  set angx to player.getangle x  set angx to angx * -1  set angx to ( ( tan angx ) * ( player.getdistance Target ) )  set angx to angx + 110  message"angle %.2f"angx          if  angx < ( Posz + 20 ) && angx >= Posz                messagebox"headshot"          endifendifend

User avatar
Sweets Sweets
 
Posts: 3339
Joined: Tue Jun 13, 2006 3:26 am

Post » Sun Aug 08, 2010 1:51 pm

This seems to work fine: the final dposZ value is the distance from the target feet to the aiming spot on the body. I suppose anything above 100 may be considered head.

Must adjust for other player positions, like sneaking or jumping.

And I think I read someone mentioning the camera stays in the same position, regardless of the race. You may want to check this.


	;=== Calc horizontal distance  === 	let posX1 := playerref.getpos x	let posY1 := playerref.getpos y	let posX2 := refTarget.getpos x	let posY2 := refTarget.getpos y	let dposX := posX1 - posX2 	let dposY := posY1 - posY2 	let disH := ( dposX * dposX ) + ( dposY * dposY )	let disH := sqrt disH	;=== Calc vertical distance (from the camera)  === 	let angX := playerref.getangle X	let disV := disH * tan angX	;=== Calc camera Z pos  === 	let refRace := playerref.getrace	let posZ := 125 * getracescale refRace  	let posZ := posZ + playerref.getpos Z  	;=== Calc aiming spot distance from target feet  === 	let dposZ := posZ - disV	let dposZ := dposZ - refTarget.getpos Z

User avatar
Lexy Corpsey
 
Posts: 3448
Joined: Tue Jun 27, 2006 12:39 am

Post » Sun Aug 08, 2010 12:56 pm

:bowdown:

I had an idea to get the height difference between the player and the target using the OBSE bounding box commands and add that to the "set Posz to Posz + 95", but it was not working all that well yet. Probably because of the camera issue you mentioned? But your script will get me out of this math oubliette and on to finish the quest I am working on. Thank you so much!

(I heard on the Bethesda Podcast that this kind of math was not absolutely necessary to work for a game developer unless you are doing programming 3d engine type work, but I am finding that hard to believe. I need to find some on line Trig class I think.)


This seems to work fine: the final dposZ value is the distance from the target feet to the aiming spot on the body. I suppose anything above 100 may be considered head.

Must adjust for other player positions, like sneaking or jumping.

And I think I read someone mentioning the camera stays in the same position, regardless of the race. You may want to check this.


[code] ;=== Calc horizontal distance ===

SNIP!


User avatar
Jonathan Montero
 
Posts: 3487
Joined: Tue Aug 14, 2007 3:22 am


Return to IV - Oblivion