SA-MP Forums Archive
[HELP]Objects+Angles[HELP]!!! - 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)
+--- Thread: [HELP]Objects+Angles[HELP]!!! (/showthread.php?tid=376917)



[HELP]Objects+Angles[HELP]!!! - Cjgogo - 12.09.2012

Okay, so I have come upon a serious problem.So far I have used only scripted DataBases, mini-games, fuel/speed system, commands, everything on my own, yet, many of you helped me when I asked for it, and I gotta say thanks.BUT now the problem is that, so far I used only algebra(my favorite part), and speed-distance physics.Now I came along a project, that I want to script, but for that, I need to understand angles.I am not saying that I don't understand them fully, but I have to use trigonometry, wich is not my favorite part of mathematics.SO, basically, I need to make an object move forward from a vehicle, and when it encounters an object/player/vehicle in its way, it explodes(Yeah, :P, a missile).BUT I may know how to make it explode(I guess I just use a loop, and check if there's any object player, or vehicle around[I am not sure if I have to use 3 loops, also give me a hint about this, please ]), but I don't know how to make it move forward.Example if I shot from a vehicle, it follows a straight trajectory, no curves, etc.(Like a normal Rocket Laucnher,NOT A HOT SEEKING ONE).Help is highly appreciated, thanks in advance, any tutorials is also appreciated, but please, just help me.


Respuesta: [HELP]Objects+Angles[HELP]!!! - Siralos - 12.09.2012

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


Re: [HELP]Objects+Angles[HELP]!!! - Cjgogo - 12.09.2012

As I said, HELP is highly appreciated, thank you very much, first of all, I was about to ask how to check if a player is aligned with an object, etc., I need it for a minigun, and this will help me I think
Код:
GetPlayerCameraFrontVector(playerid, fVX, fVY, fVZ);
Thank you very much, I am waiting for more replies, until that, REP+ for you.I know you may say that for such an answer, you wouldn't need REP++, but I want this project done so badly, that every little asnwer, wich explains a bit of code, is very useful, thanks.Waiting for more replies.


Respuesta: [HELP]Objects+Angles[HELP]!!! - Siralos - 12.09.2012

I added some code that may help you


Re: [HELP]Objects+Angles[HELP]!!! - Cjgogo - 12.09.2012

Well thanks, for hitting an object, I might have an idea:
pawn Код:
for(new i=0;i<MAX_OBJECTS;i++)
{
     if(ObjectToPoint)//same principle
}
Thanks, I had a few ideas but they were not clear


Respuesta: Re: [HELP]Objects+Angles[HELP]!!! - Siralos - 12.09.2012

Quote:
Originally Posted by Cjgogo
Посмотреть сообщение
Well thanks, for hitting an object, I might have an idea:
pawn Код:
for(new i=0;i<MAX_OBJECTS;i++)
{
     if(ObjectToPoint)//same principle
}
Thanks, I had a few ideas but they were not clear
Yes, you can all 'MissileHit' on that loop, but instead of doing MAX_OBJECTS, create an array of your own to store all 'fired' missiles. Elsewhere the timer will be too overloaded.