SA-MP Forums Archive
Detecting if a player touches an object? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Discussion (https://sampforum.blast.hk/forumdisplay.php?fid=84)
+---- Thread: Detecting if a player touches an object? (/showthread.php?tid=593207)



Detecting if a player touches an object? - Aerotactics - 02.11.2015

Say for instance a player touches or punches an object, is it detectable?


Re: Detecting if a player touches an object? - codectile - 04.11.2015

Yes it is detectable, now. Have a look at this cimulator-collision detection and physics simulation.
Need a script for demo?
check out line number, 60 and 260


Re: Detecting if a player touches an object? - Pottus - 05.11.2015

Quote:
Originally Posted by codectile
View Post
Yes it is detectable, now. Have a look at this cimulator-collision detection and physics simulation.
Need a script for demo?
check out line number, 60 and 260
With that example you would actually be better only updating the capsule position when you actually need to make a check right ?


Re: Detecting if a player touches an object? - Crayder - 05.11.2015

Yes it can be detected, but not in SA-MP natively.

codectile's plugin would not detect an actual punch on the object, just if the player's surrounding capsule would contact the object.

You could also use a ColAndreas ray cast for it, but still that is not detecting it either.

The best solution would be a client side plugin, which obviously isn't ideal.


Re: Detecting if a player touches an object? - codectile - 06.11.2015

Quote:
Originally Posted by Pottus
View Post
With that example you would actually be better only updating the capsule position when you actually need to make a check right ?
I wanted to play around with my created objects so I needed a real-time detection. A stock function can do his work.

Code:
stock IsPlayerInContact(playerid)
{
    new Float:x, Float:y, Float:z;
    GetPlayerPos(playerid, x, y, z);
    /*
     *0.3 is the radius and 0.9 is the height and I think that,
     *the second parameter is of no use so I'll remove it in the next update
    */
    CR_CreateCapsuleCharacter(playerid, 1, x, y, z, 0.3, 0.9); //you can define your own radius and height
    new check = CR_CharacterContactTest(playerid); //I'll try to add this today, most probably
    CR_DeleteCharacter(playerid);
    return check; //returns 1 if collision is detected else returns 0
}
Quote:
Originally Posted by Crayder
View Post
Yes it can be detected, but not in SA-MP natively.

codectile's plugin would not detect an actual punch on the object, just if the player's surrounding capsule would contact the object.

You could also use a ColAndreas ray cast for it, but still that is not detecting it either.

The best solution would be a client side plugin, which obviously isn't ideal.
The fact is SanAndreas itself uses simple collision shapes for player collisions. They started using rag dolls from GTA IV. Don't forget cimulator also have raytracing functionality. Ray tracing is not a good option at all, atleast not better than the capsule/cylinder/box approximations.

EDIT: for checking a punch, you should use animation checks along with IsPlayerInContact(playerid).