PDA

View Full Version : GetVehicleRotationQuat returns wrong values


Kwashiorkor
08/03/2015, 06:52 PM
I'm trying to use this to pop tires if they are shot even if the vehicle has no driver. Works perfectly with one exception: if a player touches the vehicle if it has no passengers. I checked and GetVehicleRotationQuat causes the problems. After "touching" a vehicle, it always returns strange values:
[19:19:14] HitPos = 2054.807 2593.522 7.895
[19:19:14] Quat= 0.890 -0.096 0.018 Works fine
[19:19:14] VehPos = 2055.053 2595.043 7.867
[19:19:14] OffPos = 0.949 1.710 -0.349
[19:19:20] (null)
[19:19:20] HitPos = 2054.748 2592.828 7.843
[19:19:20] Quat= ./,),(-*,(.000 0.000 0.000 Values after touching
[19:19:20] VehPos = -0.000 -0.000 7.442
[19:19:20] OffPos = 0.949 1.710 -0.349
The vehicle's position nor its rotation has changed (well, a little maybe but that's not significant). Does anyone here has a solution for this problem?

Pillhead2007
08/03/2015, 06:53 PM
Use this mate I found the function I use http://forum.sa-mp.com/showthread.php?t=529324

Pottus
08/03/2015, 07:00 PM
I know there is some issues with this function it's not really reliable in some circumstances.

Kwashiorkor
08/03/2015, 07:00 PM
@Pillhead2007: That code only uses the vehicle's rotation around the Z axis. It won't work if it's parked up- or downhill.
@Pottus: Ah, okay. Is there a fix available? And do you know under which conditions it does not work?

Pottus
08/03/2015, 07:03 PM
Well I tried to make items thrown out windows on the DayZ server but that failed to work correctly because this function is completely unreliable to the point it is not trustworthy in the slightest. My suggestion document all actual values also provide expected value when they are wrong and provide video of what happened to lead to the issue. Then post a full bug report on the issue for now there isn't much you can do it's not really a viable feature given current issues.

@Edit - There is an small work around with MapAndreas you would really need ColAndreas which can return the rx/ry angle of collision surface found anyways you can calculate the rx/ry rotation of a slope on which the vehicle is sitting with MapAndreas until ColAndreas is released. This will have some limitation such as under bridges but it should give you the correct rx/ry angle for the most part.

ColAndreas does the same thing but much more accurately.

native CA_RayCastLineAngle(Float:StartX, Float:StartY, Float:StartZ, Float:EndX, Float:EndY, Float:EndZ, &Float:x, &Float:y, &Float:z, &Float:rx, &Float:ry);

stock CalcSlopeAtPos(Float:posx, Float:posy, Float:posz, &Float:RXAngle, &Float:RYAngle)
{
new Float:North[3], Float:South[3], Float:East[3], Float:West[3], Float:opposite, Float:hypotenuse;

// Set slope positions
North[0] = posx;
North[1] = posy + 0.2;

South[0] = posx;
South[1] = posy - 0.2;

East[0] = posx + 0.2;
East[1] = posy;

West[0] = posx - 0.2;
West[1] = posy;

MapAndreas_FindZ_For2DCoord(North[0], North[1], North[2]);
MapAndreas_FindZ_For2DCoord(South[0], South[1], South[2]);
MapAndreas_FindZ_For2DCoord(North[0], East[1], East[2]);
MapAndreas_FindZ_For2DCoord(North[0], West[1], West[2]);

// Calculate Slope angles
// North South RX
hypotenuse = getdist3d(North[0], North[1], North[2], South[0], South[1], South[2]);
opposite = getdist3d(North[0], North[1], North[2], North[0], North[1], South[2]);

RXAngle = asin(floatdiv(opposite, hypotenuse));
if(South[2] > North[2]) RXAngle *= -1;

// West East RY
hypotenuse = getdist3d(West[0], West[1], West[2], East[0], East[1], East[2]);
opposite = getdist3d(West[0], West[1], West[2], West[0], West[1], East[2]);

RYAngle = asin(floatdiv(opposite, hypotenuse));
if(East[2] > West[2]) RYAngle *= -1;
}

Pottus
08/03/2015, 07:22 PM
@****** - It fucks up a lot I've experienced it.

JernejL
11/03/2015, 11:33 AM
GetVehicleRotationQuat will not return useable data unless the vehicle has a driver in it, unoccupied & passenger sync and trailer sync corrupts this data because they are not (yet) based on quaternion data, but as long as you have a driver, the data is correct.