Creating trailer behind a vehicle using GetVehicleRotationQuat
#1

Hello, as in title I need to create trailer right behind a truck and then attach trailer to it. I've run into problems though, because getting the X and Y axis of the player vehicle is only possible via GetVehicleRotationQuat - which is utterly confusing. How can I translate its result to some kind of offset to certain point? My english isn't good enough to understand the wikipedia article (good Lord, the scientific lingo is killing me).

Let's say this is form of the code
pawn Код:
CMD:addTrailer(playerid, params[]) {
    if(!IsPlayerInAnyVehicle(playerid)) return 0;
    new vid = GetPlayerVehicleID(playerid), Float:Quat[4], Float:Offset[3], Float:Pos[3], Float:Rotation;
    GetVehicleRotationQuat(vid, Quat[0], Quat[1], Quat[2], Quat[3]);
    GetVehiclePos(playerid, Pos[0], Pos[1], Pos[2]);
    //Magic happens here
    //Offsets and Rotation are calculated
    new trailer = CreateVehicle(TRAILERID, Pos[0] + Offset[0], Pos[1] + Offset[1], Pos[2] + Offset[2], Rotation, -1, -1, 0);
    AttachTrailerToVehicle(trailer, vid);
    return 1;
}
Other issue are dimensions of the vehicle itself. I need perfect distance from it, so I can attach the trailer at once, without any movement from the player.

I found https://sampforum.blast.hk/showthread.php?tid=368189 this thread, but can't make anything out of it.
Reply
#2

Why would you need the X/Y rotation to put the trailer behind the vehicle? Surely you just need the Z (rotation)..? Also it doesn't matter AT ALL in what position you place the trailer; when it is attached it's no longer in that position, is it? Just create the trailer at the same position as the vehicle.

One thing to note is that only STREAMED-IN vehicles can be attached as trailers, so you may have to put the code under OnVehicleStreamIn(ForPlayer?).
Reply
#3

Wait, I thought that AttachTrailerToVehicle doesn't magically teleport the trailer. So if I move it to OnVehicleStreamIn callback, then it will be moved to correct position?

@e:
Works like a charm, thanks man!
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)