OnPlayerWeaponShot bug
#6

Quote:
Originally Posted by AndySedeyn
Посмотреть сообщение
This has been bugging me too. Now, to clarify, I'm not the best in mathematics, but I've crafted this function to detect when a player is looking backward with their camera:

PHP код:
stock IsAimingBehind(playerid) {
    static
        
Float:cPosXFloat:cPosYFloat:cPosZ,
        
Float:pPosXFloat:pPosYFloat:pPosZ,
        
Float:cFacAngFloat:pFacAng;
    
GetPlayerPos(playeridpPosXpPosYpPosZ);
    
GetPlayerFacingAngle(playeridpFacAng);
    
GetPlayerCameraPos(playeridcPosXcPosYcPosZ);
    
cFacAng 90 + (atan2((cPosY pPosY), (cPosX pPosX)));
    static
        
Float:cOppFacAng = ((pFacAng 180) ? (pFacAng 180) : (pFacAng 180));
    return ((
cFacAng 90) < cOppFacAng < (cFacAng 90)) || ((cFacAng 90) < cOppFacAng < (cFacAng 90));

The name of the function is a bit ambiguous. It doesn't check if the player is aiming, but that's something that you can easily change.

This function does the following:
  • Calculates the facing angle of the player's camera (Not the player's character)
  • Inverses the calculated vector relative to the facing angle of the player (the character)
  • Checks if that falls within the 180° behind the player
You can use this in a looping timer to keep checking it when the player is holding KEY_HANDBRAKE / KEY_AIM (if KEY_AIM is defined in your script).

This function still needs some tweaking and improvement, but it works and can be used for now. A current improvement that I can think of is the use of GetPlayerCameraFrontVector (?). Also while testing this, I noticed that the aim angle is larger than 90° on each side, so this can be improved too.

(?): At least I think GetPlayerCameraFrontVector replaces the calculations that I've done and if so, probably does them more efficiently.

I would appreciate if someone with more insight into this stuff could and wants to help me improve this function (and also explain the process, as I'm interested in learning too)!
That's not going to solve all of your problems. If you face a wall (not aiming behind) and shoot with a Tec9 for example, it won't detect it, nor is OnPlayerWeaponShotCalled.
Reply


Messages In This Thread
OnPlayerWeaponShot bug - by Runn3R - 12.10.2016, 21:30
Re: OnPlayerWeaponShot bug - by SickAttack - 12.10.2016, 21:45
Re: OnPlayerWeaponShot bug - by Runn3R - 13.10.2016, 08:52
Re: OnPlayerWeaponShot bug - by Threshold - 15.10.2016, 12:55
Re: OnPlayerWeaponShot bug - by AndySedeyn - 06.11.2016, 22:33
Re: OnPlayerWeaponShot bug - by SickAttack - 06.11.2016, 23:43
Re: OnPlayerWeaponShot bug - by AndySedeyn - 07.11.2016, 19:09
Re: OnPlayerWeaponShot bug - by SickAttack - 07.11.2016, 19:32
Re: OnPlayerWeaponShot bug - by AndySedeyn - 07.11.2016, 19:37
Re: OnPlayerWeaponShot bug - by SickAttack - 07.11.2016, 19:40
Re: OnPlayerWeaponShot bug - by aprender123 - 08.11.2016, 18:50
Re: OnPlayerWeaponShot bug - by DTV - 10.11.2016, 01:11

Forum Jump:


Users browsing this thread: 1 Guest(s)