- Documentation
- Server functions
- attachPedToVehicle
Function
attachPedToVehicle
A ped (NPC or player) rides on the outside of a vehicle: on the step, in the truck bed or on the roof. Every player's game places it from the vehicle's position each frame, so it does not lag behind at high speed. A player is frozen meanwhile and does not collide with that vehicle.
Syntax
bool attachPedToVehicle(ped ped, vehicle vehicle [, float x = 0, float y = 0, float z = 0, float rotation = 0, string block = nil, string anim = nil])Arguments
pedped- An NPC or a player.
vehiclevehicle- The vehicle.
xfloat, optional = 0- Offset to the right of the vehicle's centre, in metres.
yfloat, optional = 0- Offset forward.
zfloat, optional = 0- Offset up.
rotationfloat, optional = 0- Rotation relative to the vehicle's heading, in degrees.
blockstring, optional = nil- Block of an animation played in a loop.
animstring, optional = nil- Animation name.
Returns
true on success.
Example
local truck = createVehicle(422, 1500, -1680, 14)
local worker = createPed(260, 1500, -1680, 15)
attachPedToVehicle(worker, truck, 0, -1.6, 0.9, 180, "ped", "SEAT_idle")
Notes
The ride ends after detachPedFromVehicle, when the vehicle is destroyed, the ped enters a vehicle or dies.
See also
detachPedFromVehicleEnds a ride started withattachPedToVehicle. The ped stays where it was riding, its collision comes back and the riding animation ends.getPedAttachedVehicleReturns the vehicle the ped is riding on, plus its offset and rotation.attachElementsAttaches an element to another. The attached element moves and rotates together with the one it is attached to. An object attached to a vehicle is carried by the game in the same frame as the vehicle physics, so it stays exactly in place even at high speed and in turns. This also applies to objects with a model loaded from a file (e.g. signs on a bus).