The online racing simulator
the actual angle of the car in relation to the direction of travel
I use default driftmeter code which tells the angle, but that's not even close. As you can see, the car is at an angle of almost 90 degrees and the meter only reads 55 degrees. I would need help to get the meters to show the right angle.
Here is my code:

<?php 
Event OnCrossingChecker
($userName,$Flags,$Time,$Object,$UserSpeed,$CircleIndex)  # Player event
    
$AngleVelocity GetCurrentPlayerVar"AngleVelocity" );

    IF ((
$Object == "1st checkpoint") && ($Flags == 2))
        
THEN
              globalmsg
(.getplayervar($userName,"NickName")."^1Entry:^3".getplayervar($userName,"InstantSpeed")." ^3km/h");
    ENDIF
    IF ((
$Flags == 0) || ($Flags == 2))
    
THEN
    
IF  ($AngleVelocity 0)
    
THEN
        $AngleVelocity 
= -$AngleVelocity ;
        
SetCurrentPlayerVar("Angle_Reverse",$AngleVelocity);
              
globalmsg(.getplayervar($userName,"NickName")." ^1Angle: ^3".GetCurrentPlayerVar"Angle_Reverse")."°");
    ELSE
              
globalmsg(.getplayervar($userName,"NickName")." ^1Angle: ^3".$AngleVelocity."°");    
    ENDIF
    ENDIF
            
EndEvent
?>


You are looking at a wrong variable, angular velocity is a quantity that describes a rotational movement of an object per units of time. What you need is heading or angle of the car with respect to track coordinate system. One more thing, these angles are usualy given in the units of radians, so you will have to do some math to convert it back to degrees.
In "Player Vars.txt", there are two variables that you need to use:

Heading, // Direction of forward axis : 0 = world y direction
Direction, // Car's motion if Speed > 0 : 0 = world y direction

First, convert them to the appropriate format.
- They might be in a byte range instead of degrees [0-255]. Simply multiply them by 360 and divide them by 255. (x * 360 / 255)
- If both of them aren't clockwise or anti-clockwise, convert one to other's. (360 - x)
- Both of them start from the same axis (+y), so you dont need to adjust it in this case.
Final format: Both of them (C +y) or (AC +y), range [0, 360].

Then all you need to do is:
- Calculate the difference between them to get the angle. Angle = abs(Heading - Direction) [0 - 360]
- If it is greater than 180, substract from 360. Angle = 360 - Angle [0 - 180]
(In case of something like Heading is 350 and Direction is 10, Angle should be 20, not 340)

Keep us updated if it works or not.
I tested this and this works but every time you have to enter the coordinates that are a fixed point in relation to the measurement point. And if i use "$GetAngleInDegree" it gives lots of decimals.

<?php 
Event OnCrossingChecker
($userName,$Flags,$Time,$Object,$UserSpeed,$CircleIndex)  # Player event
    
$GetAngleInDegrees GetAngle($userName,"-387:-635");
    
SetCurrentPlayerVar("Angle",$GetAngleInDegrees);
    IF ((
$Object == "1st checkpoint") && ($Flags == 2))
        
THEN
              globalmsg
(.getplayervar($userName,"NickName").GetCurrentPlayerVar("Angle"));
    ENDIF    
EndEvent
?>


I try do code what use direction and heading.
Quote from tumes925semut :...And if i use "$GetAngleInDegree" it gives lots of decimals.

<?php 
    $GetAngleInDegrees 
GetAngle($userName,"-387:-635");
?>


Not quite sure exactly how you could do it with that code without trial and error, but you might be able to round the angle decimals down, such as (for 2 decimal places)

$GetAngleInDegrees = GetAngle($userName,round("-387:-635"),2);

Maybe?
Quote from sinanju :Not quite sure exactly how you could do it with that code without trial and error, but you might be able to round the angle decimals down, such as (for 2 decimal places)

$GetAngleInDegrees = GetAngle($userName,round("-387:-635"),2);

Maybe?

I Got it thanks.
globalmsg(.getplayervar($userName,"NickName").Round(getplayervar($userName,"Angle"),2));

Quote from MizzMaster :In "Player Vars.txt", there are two variables that you need to use:

Heading, // Direction of forward axis : 0 = world y direction
Direction, // Car's motion if Speed > 0 : 0 = world y direction

First, convert them to the appropriate format.
- They might be in a byte range instead of degrees [0-255]. Simply multiply them by 360 and divide them by 255. (x * 360 / 255)
- If both of them aren't clockwise or anti-clockwise, convert one to other's. (360 - x)
- Both of them start from the same axis (+y), so you dont need to adjust it in this case.
Final format: Both of them (C +y) or (AC +y), range [0, 360].

Then all you need to do is:
- Calculate the difference between them to get the angle. Angle = abs(Heading - Direction) [0 - 360]
- If it is greater than 180, substract from 360. Angle = 360 - Angle [0 - 180]
(In case of something like Heading is 350 and Direction is 10, Angle should be 20, not 340)

Keep us updated if it works or not.

Now is made this code. I think it works, but when you drive from other direction angle show negative


<?php 
Event OnCrossingChecker
($userName,$Flags,$Time,$Object,$UserSpeed,$CircleIndex)  # Player event
    
$GetAngleInDegrees GetAngle($userName,"-387:-635");
    
$Heading GetCurrentPlayerVar"Heading" );      # Direction of forward axis : 0 = world y direction
    
$Direction GetCurrentPlayerVar"Direction" );    # Car's motion if Speed > 0 : 0 = world y direction
    
SetCurrentPlayerVar("Angle",$GetAngleInDegrees);
    
SetCurrentPlayerVar("RealAngle",getcurrentplayervar("Heading")-getcurrentplayervar("Direction"));    
    
globalmsg("^8head".getcurrentplayervar("Heading"));    
    
globalmsg("^8dir".getcurrentplayervar("Direction"));
  IF ( 
$Heading )
    
THEN
    SetCurrentPlayerVar
("RealAngle",getcurrentplayervar("Heading")-getcurrentplayervar("Direction"));
    
globalmsg("^1ANGLE    ".getcurrentplayervar("RealAngle"));
    ENDIF    
    
  IF ( 
$Heading 
    
THEN
    SetCurrentPlayerVar
("RealAngle",getcurrentplayervar("Heading")-getcurrentplayervar("Direction")+360);
    
globalmsg("^2ANGLE+360    ".getcurrentplayervar("RealAngle"));    
    ENDIF
ENDEvent    
?>


I found this and direction is 0-360 scaled already. Headin -179-180

Quote :+---------------------------------------------------------------+
|Changes from 7.0.7.1 to 7.0.7.2 | fixes/changes
+---------------------------------------------------------------+
=================================================
New:
=================================================

Nothing

=================================================
Changed:
=================================================

1: PlayerVar($userName,"Z"): Z-axis has now 2 decimals xx.yy
2: PlayerVar($userName,"Heading"); Heading values changed ((0 - 180 degrees) & (0 - -179) degrees) instead of 0-359 degrees
3: Message ingame when LFSLapper has been connected after (re)loading.
Handy when your LFSlapper instance is running like a service instead of an app for hosting services.

=================================================


<?php 
IF   
THEN    
SetCurrentPlayerVar
("RealAngle",getcurrentplayervar("Heading")-getcurrentplayervar("Direction")+360);
?>

I need there formula what convert negative to positive...

IF ( RealAngle == negative )
Then
Convert to positive.
ELSE


<?php 
globalmsg
("^2Oange   ".getcurrentplayervar("RealAngle"));    
ENDIF
?>

The brain is tired tonight. I've gotten a lot done with the code.
If it's any use, this is (part of) the code I use in my Drift Meter script:


<?php 
CatchEvent OnDriftScore
$userName # This is the section for displaying the Drift Meter and Drift Messages

    
$AngleVelocity GetCurrentPlayerVar"AngleVelocity" );

     IF( 
$AngleVelocity )

    
THEN
        $AngleVelocity 
= -$AngleVelocity;

        
SetCurrentPlayerVar("Angle_Reverse",$AngleVelocity);

        
openPrivButton"driftmeter_angle",$DMorigL+1,$DMorigT+13,10,12,3,-1,64,langEngine"%{driftmeter_driftanglerevbox}%" GetCurrentPlayerVar"Angle_Reverse")));

    ELSE

        
openPrivButton"driftmeter_angle",$DMorigL+1,$DMorigT+14,10,12,3,-1,64,langEngine"%{driftmeter_driftanglebox}%" $AngleVelocity ));

    ENDIF

EndCatchEvent
?>


Quote from tumes925semut :I need there formula what convert negative to positive...

If there is any abs() function, use it. (abs = absolute, if $a < 0 then $a = -$a endif)

I am not sure about the values and ranges in your code, but I can tell that you are actually measuring the angle of the car compared to its Direction instead of comparing it to the measurement line's Angle which probably what you wanted in the first place. Although this approach would give you the actual drifting angle of the car, there is no guarantee you will get 90 degrees just because you past the line like in the image. If you want that, calculate the difference between the Heading and Angle of the line instead of Direction.
Quote from MizzMaster :If there is any abs() function, use it. (abs = absolute, if $a < 0 then $a = -$a endif)

I am not sure about the values and ranges in your code, but I can tell that you are actually measuring the angle of the car compared to its Direction instead of comparing it to the measurement line's Angle which probably what you wanted in the first place. Although this approach would give you the actual drifting angle of the car, there is no guarantee you will get 90 degrees just because you past the line like in the image. If you want that, calculate the difference between the Heading and Angle of the line instead of Direction.

Here what i got.

It picks every time ELSE...


<?php 
#    globalmsg("^4test4");    
                
SetCurrentPlayerVar("RealAngle",-getcurrentplayervar("Heading")-getcurrentplayervar("Direction")-360);
            IF ( 
GetCurrentPlayerVar("RealAngle") < )
                
THEN
            
#    globalmsg("^2then");
                
SetCurrentPlayerVar("RealAnglerev",-getcurrentplayervar("RealAngle"));
                
globalmsg(.getplayervar($userName,"NickName")." ^2Anglerev:^3 ".Round(getcurrentplayervar("RealAnglerev"),0)."°");
                
            ELSE
            
#    globalmsg("^3else");
                
globalmsg(.getplayervar($userName,"NickName")." ^2Angle:^3 ".Round(getcurrentplayervar("RealAngle"),0)."°");
            ENDIF
?>

This code is extremely confusing.

First make sure that you know the range for each of variables heading and direction. Then you can start doing the math with them. Why are you doing -360? It makes no sense, rotating by full circle in any direction gets you to the same point.

If you are intereated in value of heading-direction, then put that into the if statement and ask if it is less then zero. For me it is intuitive to have the zero where car direction matches its heading, and if you drift left to show negative and drift to right to show positive angle.
Quote from rane_nbg :This code is extremely confusing.

First make sure that you know the range for each of variables heading and direction. Then you can start doing the math with them. Why are you doing -360? It makes no sense, rotating by full circle in any direction gets you to the same point.

If you are intereated in value of heading-direction, then put that into the if statement and ask if it is less then zero. For me it is intuitive to have the zero where car direction matches its heading, and if you drift left to show negative and drift to right to show positive angle.

OK but my point was that if formula and why it not work?
Here is my full code... sure shocking but come on.

<?php 
Event OnCrossingChecker
($userName,$Flags,$Time,$Object,$UserSpeed,$CircleIndex)  # Player event
    
$Heading GetCurrentPlayerVar"Heading" );      # Direction of forward axis : 0 = world y direction
    
$Direction GetCurrentPlayerVar"Direction" );    # Car's motion if Speed > 0 : 0 = world y direction
    
SetCurrentPlayerVar("RealAngle",getcurrentplayervar("Heading")-getcurrentplayervar("Direction"));
IF ( 
$Flags == )
    
THEN
    
#globalmsg("^7head ".getcurrentplayervar("Heading")." dir ".getcurrentplayervar("Direction"));    

    
IF ((( $Heading 0) && ( $Heading 90 )) && ( $Direction 225 ))  #Oange

        
THEN
        
        
IF( $Heading >  $Direction )
            
THEN
                SetCurrentPlayerVar
("RealAngle",getcurrentplayervar("Heading")-getcurrentplayervar("Direction"));            
                
globalmsg(.getplayervar($userName,"NickName")." ^2Angle:^3 ".Round(getcurrentplayervar("RealAngle"),0)."°");
            ELSE
                
SetCurrentPlayerVar("RealAngle",getcurrentplayervar("Heading")-getcurrentplayervar("Direction")-360);    
                
globalmsg(.getplayervar($userName,"NickName")." ^2Angle:^3 ".Round(getcurrentplayervar("RealAngle"),0)."°");
        ENDIF
    ENDIF    
    IF ((( 
$Heading 0) && ( $Heading 90 )) && ( $Direction 225 ))  #Oange2
        
THEN
        
IF( $Heading >  $Direction )
            
THEN
                SetCurrentPlayerVar
("RealAngle",getcurrentplayervar("Heading")-getcurrentplayervar("Direction"));            
                
globalmsg(.getplayervar($userName,"NickName")." ^2Angle:^3 ".Round(getcurrentplayervar("RealAngle"),0)."°");
            ELSE
                
SetCurrentPlayerVar("RealAngle",getcurrentplayervar("Direction")-getcurrentplayervar("Heading"));    
                
globalmsg(.getplayervar($userName,"NickName")." ^2Angle:^3 ".Round(getcurrentplayervar("RealAngle"),0)."°");
        ENDIF
    ENDIF
    
    IF ((( 
$Heading 90) && ( $Heading 180 )) && ( $Direction 315 )) #yellow
        
THEN
        
IF( $Heading >  $Direction )
            
THEN
                SetCurrentPlayerVar
("RealAngle",getcurrentplayervar("Heading")-getcurrentplayervar("Direction"));            
                
globalmsg(.getplayervar($userName,"NickName")." ^2Angle:^3 ".Round(getcurrentplayervar("RealAngle"),0)."°");
            ELSE
                
SetCurrentPlayerVar("RealAngle",getcurrentplayervar("Direction")-getcurrentplayervar("Heading"));    
                
globalmsg(.getplayervar($userName,"NickName")." ^2Angle:^3 ".Round(getcurrentplayervar("RealAngle"),0)."°");
        ENDIF
    ENDIF
    IF ((( 
$Heading 90) && ( $Heading 180 )) && ( $Direction 315 )) #yellow2
        
THEN
        
IF( $Heading $Direction )
            
THEN
                SetCurrentPlayerVar
("RealAngle",getcurrentplayervar("Heading")-getcurrentplayervar("Direction"));            
                
globalmsg(.getplayervar($userName,"NickName")." ^2Angle:^3 ".Round(getcurrentplayervar("RealAngle"),0)."°");
            ELSE
                
SetCurrentPlayerVar("RealAngle",getcurrentplayervar("Direction")-getcurrentplayervar("Heading"));    
                
globalmsg(.getplayervar($userName,"NickName")." ^2Angle:^3 ".Round(getcurrentplayervar("RealAngle"),0)."°");
        ENDIF
    ENDIF
ENDIF
IF ( 
$Flags == )
    
THEN
    
#globalmsg("^7head ".getcurrentplayervar("Heading")." dir ".getcurrentplayervar("Direction"));    
    
    
IF ((( $Heading 0) && ( $Heading > -90 )) && ( $Direction 135 ))
        
THEN
    
#globalmsg("^1test1");    
                
SetCurrentPlayerVar("RealAngle",-getcurrentplayervar("Heading")-getcurrentplayervar("Direction")-360);
                IF ( 
GetCurrentPlayerVar("RealAngle") < )
                
THEN
            
#    globalmsg("^2then");
                
SetCurrentPlayerVar("RealAnglerev",-getcurrentplayervar("RealAngle"));
                
globalmsg(.getplayervar($userName,"NickName")." ^2Anglerev:^3 ".Round(getcurrentplayervar("RealAnglerev"),0)."°");
            ELSE
                
#globalmsg("^3else");    
                
globalmsg(.getplayervar($userName,"NickName")." ^2Angle:^3 ".Round(getcurrentplayervar("RealAngle"),0)."°");
            ENDIF
    ENDIF    
    IF ((( 
$Heading 0) && ( $Heading > -90 )) && ( $Direction 135 ))
        
THEN
#    globalmsg("^2test2");    
                
SetCurrentPlayerVar("RealAngle",-getcurrentplayervar("Heading")-getcurrentplayervar("Direction"));            
                IF ( 
GetCurrentPlayerVar("RealAngle") < )
                
THEN
            
#    globalmsg("^2then");
                
SetCurrentPlayerVar("RealAnglerev",-getcurrentplayervar("RealAngle"));
                
globalmsg(.getplayervar($userName,"NickName")." ^2Anglerev:^3 ".Round(getcurrentplayervar("RealAnglerev"),0)."°");
            ELSE
                
#globalmsg("^3else"));
                
globalmsg(.getplayervar($userName,"NickName")." ^2Angle:^3 ".Round(getcurrentplayervar("RealAngle"),0)."°");
            ENDIF
    ENDIF
    
    IF ((( 
$Heading < -90) && ( $Heading > -180 )) && ( $Direction 45 ))
        
THEN
#    globalmsg("^3test3");    
                
SetCurrentPlayerVar("RealAngle",-getcurrentplayervar("Heading")-getcurrentplayervar("Direction"));
            IF ( 
GetCurrentPlayerVar("RealAngle") < )
                
THEN
            
#    globalmsg("^2then");
                
SetCurrentPlayerVar("RealAnglerev",-getcurrentplayervar("RealAngle"));
                
globalmsg(.getplayervar($userName,"NickName")." ^2Anglerev:^3 ".Round(getcurrentplayervar("RealAnglerev"),0)."°");
                
            ELSE
            
#    globalmsg("^3else");
                
globalmsg(.getplayervar($userName,"NickName")." ^2Angle:^3 ".Round(getcurrentplayervar("RealAngle"),0)."°");
            ENDIF
    ENDIF
    
    IF ((( 
$Heading < -90) && ( $Heading > -180 )) && ( $Direction 45 ))
        
THEN
    
#globalmsg("^4test4");    
                
SetCurrentPlayerVar("RealAngle",-getcurrentplayervar("Heading")-getcurrentplayervar("Direction")-360);
            IF ( 
GetCurrentPlayerVar("RealAngle") < )
                
THEN
            
#    globalmsg("^2then");
                
SetCurrentPlayerVar("RealAnglerev",-getcurrentplayervar("RealAngle"));
                
globalmsg(.getplayervar($userName,"NickName")." ^2Anglerev:^3 ".Round(getcurrentplayervar("RealAnglerev"),0)."°");
                
            ELSE
            
#    globalmsg("^3else");
                
globalmsg(.getplayervar($userName,"NickName")." ^2Angle:^3 ".Round(getcurrentplayervar("RealAngle"),0)."°");
            ENDIF
    ENDIF
ENDIF
    
EndEvent
?>



FGED GREDG RDFGDR GSFDG