Calculating coords for points behind vehicle (math)
#1

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
Reply
#2

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:yFloat:distance)
{
    new 
Float:a;
    
GetVehiclePos(vehicleidxya);
    
GetVehicleZAngle(vehicleida);
    
+= (distance floatsin(-adegrees));
    
+= (distance floatcos(-adegrees));

Reply
#3

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 )
Reply
#4

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(Floatangle, &Float:x, &Float:yFloat:distance) {
    
-= distance floatsin(angledegrees);
    
+= distance floatcos(angledegrees);

PHP код:
new FloatxFloatyFloatzFloata;
GetVehiclePos(vehicleidxyz); 
GetVehicleZAngle(vehicleida); // a is facing to the front
// a + 180 = behind | a - 90 = right | a + 90 = left
GetInFrontOfAngle(180.0xy5.0); // 5.0 behind vehicle center
GetInFrontOfAngle(90.0xy3.0); // 5.0 behind, 3.0 to the right
// save current position in new variables
new FloatfirstX xFloatfirstY y;
GetInFrontOfAngle(90.0xy7.0); // 5.0 behind, 4.0 (3.0 - 7.0) to the left
new FloatsecondX xFloatsecondY y;
// and so on 
For the quat solution search for an include
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)