How to find vehicle's XY velocity?
#1

I mean something like:

If the vehicle is going to the right side x is +.
If the vehicle is going to the left side x is -.
If the vehicle is going forward y is +.
If the vehicle is going backward y is -.

Doesn't matter where the vehicle is facing at...
pawn Код:
(+y)      
     .            
     .          
     .          
     .          
(-x)---- ˄ ---- (+x)    
     .          
     .          
     .          
     .          
    (-y)

those are x and y velocity of a vehicle driving to the north of the map.
pawn Код:
(-x)
     .
     .
     .
     .
(-y) ---- > ---- (y)
     .
     .
     .
     .
     (+x)

those are x and y velocity of a vehicle driving to the right of the map.
How do I get that?
Reply
#2

*Bump*
Reply
#3

https://sampwiki.blast.hk/wiki/GetVehicleVelocity
Reply
#4

Quote:
Originally Posted by ¤Adas¤
I will mind next time before making myself a dumbass.
You don't get it, GetVehicleVelocity(playerid, x, y, z) return the velocity to the point(s) of the map the vehicle is going, meaning if you're going to the north (facing 90є) you won't get any speed for X. I would like to get the speed as on the code I posted. For example, the car is driving forward, y is gonna be 1 m/s for example... if you get crashed in the left side you'll get a negative X speed and so, doesn't matter where the car is facing at.
Reply
#5

Use my function GetVehicleForwardVelocity...
Reply
#6

Quote:
Originally Posted by ¤Adas¤
Use my function GetVehicleForwardVelocity...
You made a SetVehicleForwardVelocity(), not a GetVehicleForwardVelocity()...
Reply
#7

Sorry.

pawn Код:
stock Float:VehicleAngle(vehicleid)
{
new Float:Angle;
GetVehicleZAngle(vehicleid, Angle);
return Angle;
}

stock GetVehicleForwardVelocity(vehicleid, &Float:Velocity, &Float:Z)
{
new Float:SpeedX, Float:SpeedY, Float:SpeedZ;
GetVehicleVelocity(vehicleid, SpeedX, SpeedY, SpeedZ);
SpeedX *= floatsin(-VehicleAngle(vehicleid), degrees);
SpeedY *= floatcos(-VehicleAngle(vehicleid), degrees);
Velocity = floatadd(SpeedX, SpeedY);
Z = SpeedZ;
return true;
}
Reply
#8

Quote:
Originally Posted by ¤Adas¤
Sorry.

pawn Код:
stock Float:VehicleAngle(vehicleid)
{
new Float:Angle;
GetVehicleZAngle(vehicleid, Angle);
return Angle;
}

stock GetVehicleForwardVelocity(vehicleid, &Float:Velocity, &Float:Z)
{
new Float:SpeedX, Float:SpeedY, Float:SpeedZ;
GetVehicleVelocity(vehicleid, SpeedX, SpeedY, SpeedZ);
SpeedX *= floatsin(-VehicleAngle(vehicleid), degrees);
SpeedY *= floatcos(-VehicleAngle(vehicleid), degrees);
Velocity = floatadd(SpeedX, SpeedY);
Z = SpeedZ;
return true;
}
Thanks, I'll test...

Edit:
Doesn't work as I want:



(Y should be something there and X should be 0).

You can see that while you're driving forward X should be 0 and Y should be +. If you're driving side ways X should be something while Y nothing. I had to modify your funtion to get X and Y instead of they both mixed:
pawn Код:
stock GetVehicleForwardVelocity(vehicleid, &Float:y, &Float:x, &Float:Z)
{
    new Float:SpeedX, Float:SpeedY, Float:SpeedZ;
    GetVehicleVelocity(vehicleid, SpeedX, SpeedY, SpeedZ);
  GetVehicleZAngle(vehicleid, SpeedZ);
    SpeedX *= floatsin(-SpeedZ, degrees);
    SpeedY *= floatcos(-SpeedZ, degrees);

    y = SpeedY;
    x = SpeedX;
    Z = SpeedZ;

    return true;
}
That returns + in X if you're driving to the east or west and + in Y if you're driving to the north or south.
Reply
#9

I was actually wondering how to do this, too.
Reply
#10

Quote:
Originally Posted by Phyc0™
I was actually wondering how to do this, too.
<3, anyone?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)