Hello everyone,
I know that UDK is barely alive nowadays, but I have seen some people asking questions and actually receiving helpful answers, so any help will be appreciated.
I want to implement a damage indicator in my udk fps game. Nothing too fancy just like any fps game, a player gets shot an indicator appears pointing at the direction of the enemy. I tried multiple solutions but i still didnt get what i want. I am working on editing and adjusting the default UDK .uc scripts and classes.
1 Like
I think you can implement your requirement with functions like below.
function bool IsSameOrInsideInInt( int iStartIn, int iParaIn, int iEndIn ){
return ( ( iStartIn <= iParaIn ) && ( iParaIn <= iEndIn ) );
}//IsSameOrInsideInInt()
function float ConvertDotProduct2Degree( float fParaDotProductIn ){
//- This function converts dot product to degree.
//- The return value type is 'DEGREE', not 'RADIAN'!!!!!! >_<
//var-s
local float fRet;
//var-e
//impl-s
fRet = acos( fParaDotProductIn ) * RadToDeg;
//- The above sentence has the same meaning as the formula below.
// fRet = acos( fParaDotProductIn ) * ( 180.0f / Pi );
//impl-e
return fRet;
}//ConvertDotProduct2Degree()
function float GetDegreeInOnlyPlus( float fParaDegreeIn ){
//- This function converts the value of 'fParaIn' to a value between 0 and 359.9999f.
//var-s
local float fRet;
local bool bNegative40;
local float fTmp0th50;
//var-e
//impl-s
bNegative40 = ( fParaDegreeIn < 0.0f );
fTmp0th50 = ( bNegative40 )? -fParaDegreeIn: fParaDegreeIn;
fTmp0th50 = fTmp0th50 % 360.0f;
fRet = fTmp0th50;
if( bNegative40 )fRet = 360.0f - fRet;
//impl-e
return fRet;
}//GetDegreeInOnlyPlus()
function bool CalcLengthN12HourIndexByProjectileNPlayer(
out float fLenOfResultOut,
out int i12HourIdxOfResultOut,
Vector vecStartPosOfProjectileIn,
Vector vePlayerPosIn, Vector vecPlayerFrontDirIn, Vector vecPlayerRightDirIn
){
//- This function calculates the index and length, which means the direction from
// the player's position to the starting position of the projectile.
//- If ( fLenOfResultOut == 0.0f ),
// the projectile's start position and the player's location are too close to each other to be calculated.
// (This rarely happens.)
//- If ( bRet == TRUE ), it means that the direction and length have been calculated.
//- The value of 'i12HourIdxOfResultOut' ranges from 0 to 11.
//var-s
local bool bRet;
local Vector vecTmp0th30, vecTmp1st31, vecTmp2nd32;
local Vector vecTmpGoalDir33;
local float fTmpGnrDegree50, fTmpPlusDegree51;
local int iTmpPlusDegree52;
local int iTmpDivNum53, iTmpDivRemain54;
//var-e
//impl-s
//ready-s
bRet = FALSE;
fLenOfResultOut = 0.0f;
i12HourIdxOfResultOut = 0;
//ready-e
//0
vecTmp1st31 = vecStartPosOfProjectileIn;
vecTmp2nd32 = vePlayerPosIn;
vecTmp1st31.z = vecTmp2nd32.z;//~ This part treats the height values of two vectors as the same.
vecTmp0th30 = vecTmp1st31 - vecTmp2nd32;
vecTmpGoalDir33 = Normal( vecTmp0th30 );
//1
fLenOfResultOut = VSize( vecTmp0th30 );
if( fLenOfResultOut >= 1.0f ){
fTmpGnrDegree50 =
ConvertDotProduct2Degree( vecPlayerFrontDirIn dot vecTmpGoalDir33 )
* (
( ( vecPlayerRightDirIn dot vecTmpGoalDir33 ) > 0.0f )? 1.0f: -1.0f
);
fTmpPlusDegree51 = GetDegreeInOnlyPlus( fTmpGnrDegree50 );
iTmpPlusDegree52 = int( fTmpPlusDegree51 );
iTmpDivNum53 = iTmpPlusDegree52 / 30;
iTmpDivRemain54 = iTmpPlusDegree52 % 30;
i12HourIdxOfResultOut = iTmpDivNum53;
if( ( float( iTmpDivRemain54 ) / 30.0f ) >= 0.5f )++i12HourIdxOfResultOut;
if( i12HourIdxOfResultOut >= 12 )i12HourIdxOfResultOut -= 12;
if( IsSameOrInsideInInt( 0, i12HourIdxOfResultOut, 11 ) ){
//fLenOfResultOut => nop. ~ This was already calculated above.
//i12HourIdxOfResultOut => nop. ~ This was already calculated above.
bRet = TRUE;
}else{
`log(
"KhaSysGiSubRot::CalcLengthN12HourIndexByProjectileNPlayer(): bad ctrl #8534(idx=["$
i12HourIdxOfResultOut $"])...err"
);
}//else
}else{
fLenOfResultOut = 0.0f;//~ It's too close.
i12HourIdxOfResultOut = 0;
bRet = TRUE;
}//else
//impl-e
return bRet;
}//CalcLengthN12HourIndexByProjectileNPlayer()
If you use CalcLengthN12HourIndexByProjectileNPlayer(), you can calculate the direction from 0 o’clock to 11 o’clock that the player of the game was hit by the bullet. The calculated value is stored in ‘i12HourIdxOfResultOut’.
Good luck.