Some trig, and packer dimensions are screwed up. -
Misiur - 19.03.2013
There is basic idea. Let's create SetVehiclePos which works with front bumper position, not center of vehicle (front wheels aren't good either). So I've begun
pawn Код:
SetVehicleFrontBumperPos(vid, Float:x, Float:y, Float:z, Float:angle) {
new
Float:sin = floatsin(-angle, degrees),
Float:cos = floatcos(angle, degrees),
model = GetVehicleModel(vid),
Float:fD[3];
GetVehicleModelInfo(model, VEHICLE_MODEL_INFO_SIZE, fD[0], fD[1], fD[2]);
//Let's get half of vehicle length
//x /= 2 won't work for floats
fD[0] = fD[0] / 2;
fD[1] = fD[1] / 2;
x -= (fD[0] * cos) - (fD[1] * sin);
y -= (fD[1] * cos) - (fD[0] * sin);
SetVehicleZAngle(vid, angle);
return SetVehiclePos(vid, x, y, z);
}
I'm testing with angle = 175, so the x coords are completely screwed up, but y work quite nicely. After commenting the x axis I got something like
http://imgur.com/a/ZWTkv - damnit, packer is screwed up. It's longer in the back than in the front. Any idea how to fix this? (_not_ using front wheel position, as it won't be the same)
Re: Some trig, and packer dimensions are screwed up. -
Misiur - 19.03.2013
I hope that's only exception. Now - I'd like the function to work properly for any angle provided - I had trigonometry in school, and I know how to use it, but somehow GTA Units are diffrent from stuff I know.

The light blue line is fD[1] / 2 - half of the vehicle length
pawn Код:
GetVehicleModelInfo(model, VEHICLE_MODEL_INFO_SIZE, fD[0], fD[1], fD[2]);
fD[0] = fD[0] / 2;
fD[1] = fD[1] / 2 - (443 == model ? 4.2 : 0.0);
x -= fD[1] * sin;
y -= fD[1] * cos;
Should I change anything in here?
Re: Some trig, and packer dimensions are screwed up. -
Stylock - 19.03.2013
The second code should work, but you need to use negative angle in both floatsin and floatcos.
Re: Some trig, and packer dimensions are screwed up. -
Misiur - 19.03.2013
I tried following
https://sampforum.blast.hk/showthread.php?tid=416752 thread, but I don't know which theory is right in the end. I assumed that version with swapped Y angle (0 <=> 270) is correct, but I still don't get all those angles swapping ways (yeah, I'm one of those guys who copy all equations without looking at them)
Re: Some trig, and packer dimensions are screwed up. -
Stylock - 19.03.2013
I don't know anything about swapped Y angles. This is how GTA SA rotations are:
Код:
north (0)
|
(90) west- -east (270)
|
south (180)
https://sampwiki.blast.hk/wiki/SetPlayerFacingAngle
Re: Some trig, and packer dimensions are screwed up. -
Misiur - 19.03.2013
I meant to say Y axis, sorry. And I promise I won't eat shredded wheat. Well, swapping cosine as well makes sense. Thanks
#e:
@****** I meant that I never paid attention to functions using trigonometry, sheesh