PDA

View Full Version : GetVehicleRotationQuat always returning {0.5, 0.5, 0.5, 0.5} after spawning


ikkentim
14/11/2013, 12:06 PM
Hi,,

I have this code:

CreateVehicle(vehicletype, 0, 0, 5, any_rotation, -1, -1, -1);
new Float:q[4];
GetVehicleRotationQuat(vehicleid, q[0], q[1], q[2], q[3]);
printf("QUAT: %f %f %f %f", q[0], q[1], q[2], q[3]);


This always prints "QUAT: 0.5 0.5 0.5 0.5" when spawning a vehicle with any rotation. I've read somewhere this is a known bug. After a player enters the vehicle it works as it should...

Is there a way to work around this issue?

ikkentim
15/11/2013, 07:00 AM
Bump
(I know it hasn't been exactly 24hrs, but it was very much snowed under and i don't expect an answer on page 4)

ikkentim
18/11/2013, 03:29 PM
Bump

NaS
18/11/2013, 04:24 PM
I don't think bumping will result in real answers, except "stop bumping" etc... Since nobody seems to have an answer.

It's a SAMP problem, since the vehicle wasn't updated yet (or st. like this).

Try if GetVehicleZAngle returns a correct value after spawning. If not, I guess your question is answered.

There is actually no real fix, but since YOU spawn the vehicle, you have the rotation already right?

ikkentim
18/11/2013, 04:35 PM
yup, and i am storing it, but i need to know a way/moment when to re-apply the rotation to fix the problem; I want a player to interact with with the vehicle (standing behind it; i'm using the mathplugin which uses GetVehicleRotationQuat to determine the rotation) while no-one has entered the vehicle yet.

ikkentim
18/11/2013, 06:58 PM
I ended up not using the math plugin due to this issue. the rotationquat doesn't seem to update while no player is inside the vehicle.

Here is my resulting method if anyone cares:

stock IsPlayerAtVehicleTrunk(playerid, vehicleid)
{
new Float:sizex, Float:sizey, Float:unused, Float:bumperz,
Float:posx, Float:posy, Float:posz, Float:posa;

//Get all required data
GetVehicleModelInfo(GetVehicleModel(vehicleid), VEHICLE_MODEL_INFO_SIZE, sizex, sizey, unused);
GetVehicleModelInfo(GetVehicleModel(vehicleid), VEHICLE_MODEL_INFO_REAR_BUMPER_Z, unused, unused, bumperz);
GetVehiclePos(vehicleid, posx, posy, posz);
GetVehicleZAngle(vehicleid, posa);

//A check to determine if the player is actually near the vehicle.
//If the player is not near the vehicle we can stop this script from doing more 'complex' calculations.
if(!IsPlayerInRangeOfPoint(playerid, sizey, posx, posy, posz))
return 0;

//Calculate trunk position
posx += (sizey / 2) * floatsin(-posa + 180, degrees);
posy += (sizey / 2) * floatcos(-posa + 180, degrees);
posz += bumperz;

return IsPlayerInRangeOfPoint(playerid, sizex / 2, posx, posy, posz);
}

NaS
18/11/2013, 07:31 PM
That's the more easy way, yeah.

Is it a Math Plugin issue or does your code work even with just spawned vehicles?

ikkentim
18/11/2013, 09:32 PM
It's an issue with SA-MP; you can't rely on GetVehicleRotationQuat when the vehicle isn't ocupied. Since the math plugin uses GetVehicleRotationQuat, it may return faulty information. GetVehicleZAngle, however, returns the right information even when the vehicle isn't ocupied. But you can't calculate the exact trunk location due to not taking the x and y rotations in consideration in the calculation.

whatthefuck123
18/11/2013, 10:24 PM
in ur code u didnt define vehicleid
maybe this the problem? look for silly mistakes too

if ur taking the quat right after creating veh /spawning it might not work try making timer?

experiment with it, but i see you might have solved it different way now

ikkentim
18/11/2013, 10:27 PM
It never works when there is not player in the vehicle, i thoroughly tested it :(

Memoryz
18/11/2013, 10:38 PM
After the vehicle is created (CreateVehicle whatever you use), try SetVehicleToRespawn (http://wiki.sa-mp.com/wiki/SetVehicleToRespawn) and then fetch the RotationQuat, does that fix the issue or does it still exist?

Now that I'm thinking about it, the server always thinks RotationQuat is that default value because it doesn't perform any of the physics on the vehicles, the client does, so the client reports back what it was for them and the server stores that information.

ikkentim
18/11/2013, 10:43 PM
Now that I'm thinking about it, the server always thinks RotationQuat is that default value because it doesn't perform any of the physics on the vehicles, the client does, so the client reports back what it was for them and the server stores that information.

Thats what i thought as well, and why i came to the conclusion i had to use the z-angle instead of the quaternions.

Memoryz
18/11/2013, 10:49 PM
Thats what i thought as well, and why i came to the conclusion i had to use the z-angle instead of the quaternions.

I think you could probably work something out with MapAndreas, althought I'm not sure it would be very accurate but the way I would do it is check the Z heights of the coordinates around the vehicle and calculate what part of the car would have X value for its RotationQuat. Although it is a very "hacky" way of doing it :P

NaS
18/11/2013, 11:22 PM
Too inefficient, calculating so many things would be possible, but is not needed in any way.
The GetVehicleZAngle code he worked out is probably the best way to do it, since it's just a simple math calculation, not using any complex function (like MapAndreas would).

Memoryz
18/11/2013, 11:24 PM
Too inefficient, calculating so many things would be possible, but is not needed in any way.
The GetVehicleZAngle code he worked out is probably the best way to do it, since it's just a simple math calculation, not using any complex function (like MapAndreas would).

That's only if you want the ZAngle, I merely suggested a "hacky" way of getting the quats.