Detecting if a player touches an object?
#1

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

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
Reply
#3

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 ?
Reply
#4

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.
Reply
#5

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).
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)