• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Pawn] Vehicle collision with object
#3
Here's a basic outline of how you can implement this:

Create the rocket object when fired from a vehicle.
Track the movement of the rocket using OnPlayerObjectMoved.
Check for collisions between the rocket and nearby vehicles in the callback.
Here's an example code to demonstrate this:

PHP Code:
forward OnPlayerObjectMoved(playeridobjectid);

public 
OnPlayerObjectMoved(playeridobjectid)
{
    new Float:xFloat:yFloat:z;
    GetObjectPos(objectidxyz); // Get the current position of the object

    new Float:minXFloat:maxXFloat:minYFloat:maxYFloat:minZFloat:maxZ;
    GetObjectBoundingBox(objectidminXminYminZmaxXmaxYmaxZ); // Get the bounding box of the object

    new Float:vXFloat:vYFloat:vZ;
    for (new 0MAX_PLAYERSi++)
    {
        if (IsPlayerConnected(i) && != playerid)
        {
            GetPlayerPos(ivXvYvZ); // Get the position of each player

            // Check if the player's position is within the bounding box of the rocket object
            if (vX >= minX && vX <= maxX && vY >= minY && vY <= maxY && vZ >= minZ && vZ <= maxZ)
            {
                // Player i collided with the rocket object
                // You can perform actions here, such as damaging the vehicle or player
                SendClientMessage(playeridCOLOR_RED"Rocket collided with a vehicle!");
                // Destroy the rocket object
                DestroyObject(objectid);
                return 1;
            }
        }
    }
    return 0;

  Reply


Messages In This Thread
Vehicle collision with object - by illiker58 - 2023-12-29, 04:11 PM
RE: Vehicle collision with object - by N0FeaR - 2024-03-03, 04:32 PM

Forum Jump: