Determine if a vehicle passes in front of a player...
#1

As the title says;

Is it possible to determine if a vehicle passes the front of a player, and if so, how?
Reply
#2

what do u mean if a player is near a vehicle?

or

A vehicles drives into a player?

or

Vehicle is moving near a player?
Reply
#3

Quote:

if a vehicle passes the front of a player

I'm not sure how else to put that. Maybe...

If a vehicle drives in front of a player, can I determine if they drove IN FRONT of the player?
Reply
#4

Is called Physics ...... U need to get there angles..... and determine it from equations, basic physics is going to be needed to determine this

https://sampwiki.blast.hk/wiki/GetPlayerFacingAngle
https://sampwiki.blast.hk/wiki/GetVehicleZAngle
https://sampwiki.blast.hk/wiki/GetVehicleRotationQuat
http://en.wikipedia.org/wiki/Quatern...atial_rotation

These are very key and after alot of testing and tweeking i think you will be able to create a code where u will be able to find the vehicle position to the player

I thought it might of been something as easy
getting the player angle and vehicle and if the angle is near 180( the difference ) then you that the angle of the vehicle is opposite to the player......

But i am not to sure ... i do a little digging around for u see if i see something maybe even try to code and inbox u it.... But for now that my solution for solving your problem
Reply
#5

PHP код:
stock GetDistanceToCar(playeridvehFloatposX 0.0FloatposY 0.0FloatposZ 0.0) {
    new
        
FloatFloats[2][3];
    if(
posX == 0.0 && posY == 0.0 && posZ == 0.0) {
        if(!
IsPlayerInAnyVehicle(playerid)) GetPlayerPos(playeridFloats[0][0], Floats[0][1], Floats[0][2]);
        else 
GetVehiclePos(GetPlayerVehicleID(playerid), Floats[0][0], Floats[0][1], Floats[0][2]);
    }
    else {
        
Floats[0][0] = posX;
        
Floats[0][1] = posY;
        
Floats[0][2] = posZ;
    }
    
GetVehiclePos(vehFloats[1][0], Floats[1][1], Floats[1][2]);
    return 
floatround(floatsqroot((Floats[1][0] - Floats[0][0]) * (Floats[1][0] - Floats[0][0]) + (Floats[1][1] - Floats[0][1]) * (Floats[1][1] - Floats[0][1]) + (Floats[1][2] - Floats[0][2]) * (Floats[1][2] - Floats[0][2])));

Reply
#6

Ah okay. I was really looking for an easier solution because I really don't even want to attempt to get into any of that kind of crap right now. Actually, I kind of figured someone had already made a piece of code that did this. Who knows.

Either way, thank you!

EDIT: @ Magic_Time: That isn't really going to determine if a vehicle passes in front of a player, though. Is it?
Reply
#7

Maybe you can modify this:

PHP код:
forward GetXYInFrontOfPlayer2(playerid, &Float, &Float:yFloat:distanceFloat:angle);
public 
GetXYInFrontOfPlayer2(playerid, &Float, &Float:yFloat:distanceFloat:angle) {
    new 
Float:a;
    
GetPlayerPos(playeridxya);
    
GetPlayerFacingAngle(playerida);
    if (
GetPlayerVehicleID(playerid))
        
GetVehicleZAngle(GetPlayerVehicleID(playerid), a);
    
+= angle;
    
+= (distance floatsin(-adegrees));
    
+= (distance floatcos(-adegrees));

Reply
#8

Ah, very well.

Thank you.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)