[HELP]Objects+Angles[HELP]!!!
#2

Hi,

I will try to give you some tips:

First of all:
pawn Код:
GetPlayerCameraPos(playerid, fPX, fPY, fPZ);
GetPlayerCameraFrontVector(playerid, fVX, fVY, fVZ);
Then, you have your camera pos, and your camera front vector.
Now, find the x/y you are pointing to: (You need to set a MAX_DISTANCE for the object, maybe even 1000.0)
pawn Код:
object_x = fPX + floatmul(fVX, MAX_DISTANCE);
object_y = fPY + floatmul(fVY, MAX_DISTANCE);
object_z = fPZ + floatmul(fVZ, MAX_DISTANCE);
Now you have the final x/y/z position of the object
Then, get your object position and do a MoveObject...
Set a timer each 200ms and check:
1) If it hits the ground (Using MAPAndreas, for example)
2) If it's near a vehicle/player

Small code for the 'hit'
pawn Код:
MissileHit(objectid)
{
    new Float:px, Float:py, Float:pz;
    GetObjectPos(objectid, px, py, pz);
   
    for(new i=0; i<MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i) && PlayerToPoint(1.0,playerid,px, py, pz))
        {
            DestroyObject(objectid);
            CreateExplosion(px, py, pz, 3, 20);
            return 1;
        }
    }
   
    for(new i=0; i<MAX_VEHICLES; i++)
    {
        if(GetVehicleModel(i) > 0 && VehicleToPoint(2.0, i, px, py, pz)
        {
            DestroyObject(objectid);
            CreateExplosion(px, py, pz, 3, 20);
            return 1;
        }
    }
    return 0;
}


stock VehicleToPoint(Float:radi, vehid, Float:x, Float:y, Float:z)
{
    new Float:oldposx, Float:oldposy, Float:oldposz;
    new Float:tempposx, Float:tempposy, Float:tempposz;
    GetVehiclePos(playerid, oldposx, oldposy, oldposz);
    tempposx = (oldposx -x);
    tempposy = (oldposy -y);
    tempposz = (oldposz -z);
    if (((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi)))
    {
        return 1;
    }
    return 0;
}

stock PlayerToPoint(Float:radi, playerid, Float:x, Float:y, Float:z)
{
    new Float:oldposx, Float:oldposy, Float:oldposz;
    new Float:tempposx, Float:tempposy, Float:tempposz;
    GetPlayerPos(playerid, oldposx, oldposy, oldposz);
    tempposx = (oldposx -x);
    tempposy = (oldposy -y);
    tempposz = (oldposz -z);
    if (((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi)))
    {
        return 1;
    }
    return 0;
}
And perhaps, if it reaches its final destination... (OnObjectMoved), make it explode with:
DestroyObject...
CreateExplosion...

The problem is finding out if it has hit a building...
Reply


Messages In This Thread
[HELP]Objects+Angles[HELP]!!! - by Cjgogo - 12.09.2012, 07:58
Respuesta: [HELP]Objects+Angles[HELP]!!! - by Siralos - 12.09.2012, 08:19
Re: [HELP]Objects+Angles[HELP]!!! - by Cjgogo - 12.09.2012, 08:27
Respuesta: [HELP]Objects+Angles[HELP]!!! - by Siralos - 12.09.2012, 08:33
Re: [HELP]Objects+Angles[HELP]!!! - by Cjgogo - 12.09.2012, 08:41
Respuesta: Re: [HELP]Objects+Angles[HELP]!!! - by Siralos - 12.09.2012, 08:45

Forum Jump:


Users browsing this thread: 1 Guest(s)