View Single Post
Old 29/06/2013, 05:39 PM  
PeppeAC
Big Clucker
 
Join Date: Jun 2013
Location: Trani, Italy
Posts: 88
Reputation: 190
Default Re: [alpha] Objects Physics - Handle objects collisions and more.

New example command:
Code:
command(launch, playerid, params[])
{
	#define SPEED (10.0)
	#define Z_SPEED (4.0)
	#define GRAVITY (13.0)
        new modelid = 348; // Deagle Model ID
	new Float:x, Float:y, Float:z, Float:ang;
	GetPlayerPos(playerid, x, y, z);
	GetPlayerFacingAngle(playerid, ang);
	new obj = CreateObject(modelid, x, y - 0.5 * floatcos(-(ang + 90.0), degrees), z, 93.7, 120.0, ang + 60.0);
 	PHY_InitObject(obj);
	PHY_SetObjectVelocity(obj, SPEED * floatsin(-ang, degrees), SPEED * floatcos(-ang, degrees), Z_SPEED);
	PHY_SetObjectFriction(obj, 100); // This will stop the object when it touchs the ground.
	PHY_SetObjectGravity(obj, GRAVITY);
	PHY_SetObjectZBound(obj, z - 1.0, _, 0.0);
	ApplyAnimation(playerid,"GRENADE","WEAPON_throwu",3.0,0,0,0,0,0);
	return 1;
}
Throws a deagle (you can change easily the object modelid, but this code works well specially for weapons) in front of the player. You can adjust SPEED, Z_SPEED and GRAVITY to obtain a realistic effect.

Last edited by PeppeAC; 20/09/2014 at 08:33 AM.
PeppeAC is offline   Reply With Quote