Calculating coords for points behind vehicle (math) -
Riwerry - 10.09.2018
Hi guys, what I'm trying to achieve is 4 points (each with x, y, z) behind the vehicle (imagine it as cube). Furthest I got is position behind the vehicle (had function for this). And here's the point of my question, how I can add or substract X Y coordinates from those I got from behind of the vehicle so it would work on different facing angle? Thanks a lot
Re: Calculating coords for points behind vehicle (math) -
AmirSavand - 10.09.2018
I don't know the math for this, but I have this function which gets in-front of/behind vehicle.
I think this could help, you just need to move this point to left and right 2 times with different distance.
PHP код:
stock GetInFrontOfVehicle(vehicleid, &Float:x, &Float:y, Float:distance)
{
new Float:a;
GetVehiclePos(vehicleid, x, y, a);
GetVehicleZAngle(vehicleid, a);
x += (distance * floatsin(-a, degrees));
y += (distance * floatcos(-a, degrees));
}
Re: Calculating coords for points behind vehicle (math) -
Riwerry - 10.09.2018
Yes, I have this too. But from those coords I need to add/substract position based on angle (as you say to the left or right

)
Re: Calculating coords for points behind vehicle (math) -
Nero_3D - 10.09.2018
You could use the ZAngle but that will only work on flat ground, to do that accurate you need to use
GetVehicleRotationQuat
Combine one of these with
GetVehicleModelInfo to get behind (+ your offset) of the vehicle
For the ZAngle you could reuse this function
PHP код:
GetInFrontOfAngle(Float: angle, &Float:x, &Float:y, Float:distance) {
x -= distance * floatsin(angle, degrees);
y += distance * floatcos(angle, degrees);
}
PHP код:
new Float: x, Float: y, Float: z, Float: a;
GetVehiclePos(vehicleid, x, y, z);
GetVehicleZAngle(vehicleid, a); // a is facing to the front
// a + 180 = behind | a - 90 = right | a + 90 = left
GetInFrontOfAngle(a + 180.0, x, y, 5.0); // 5.0 behind vehicle center
GetInFrontOfAngle(a - 90.0, x, y, 3.0); // 5.0 behind, 3.0 to the right
// save current position in new variables
new Float: firstX = x, Float: firstY = y;
GetInFrontOfAngle(a + 90.0, x, y, 7.0); // 5.0 behind, 4.0 (3.0 - 7.0) to the left
new Float: secondX = x, Float: secondY = y;
// and so on
For the quat solution
search for an include