File tree Expand file tree Collapse file tree 3 files changed +12
-8
lines changed
Expand file tree Collapse file tree 3 files changed +12
-8
lines changed Original file line number Diff line number Diff line change @@ -6238,7 +6238,8 @@ MonoBehaviour:
62386238 m_Name:
62396239 m_EditorClassIdentifier:
62406240 Wheel: {fileID: 693784637}
6241- TicksPerRevolution: 16
6241+ PPR: 16
6242+ GearRatio: 120
62426243--- !u!1 &157527723 stripped
62436244GameObject:
62446245 m_CorrespondingSourceObject: {fileID: 100000, guid: c26a14e8dfb5c1b4783950e8573f3bd6,
@@ -52407,7 +52408,8 @@ MonoBehaviour:
5240752408 m_Name:
5240852409 m_EditorClassIdentifier:
5240952410 Wheel: {fileID: 281874620}
52410- TicksPerRevolution: 16
52411+ PPR: 16
52412+ GearRatio: 120
5241152413--- !u!1001 &1474921031
5241252414PrefabInstance:
5241352415 m_ObjectHideFlags: 0
Original file line number Diff line number Diff line change @@ -6,12 +6,14 @@ public class WheelEncoder : MonoBehaviour
66{
77 /*
88 This script attaches an incrementel encoder to a 'WheelCollider' component.
9- The property `TicksPerRevolution` sets the encoder resolution and is used to
10- measure the encoder ticks and the angle turned by the wheel.
9+ The property `PPR` sets the encoder resolution while `GearRatio` sets the
10+ multiplier due to the motor gearbox. The two parameters are used to compute
11+ the encoder ticks and the angle turned by the wheel.
1112 */
1213
1314 public WheelCollider Wheel ;
14- public int TicksPerRevolution ;
15+ public int PPR ;
16+ public int GearRatio ;
1517
1618 private float TotalRevolutions = 0f ;
1719 private int TotalTicks = 0 ;
@@ -31,8 +33,8 @@ void FixedUpdate()
3133 {
3234 float RPS = Wheel . rpm / 60f ; // Read the current wheel RPM and convert to RPS
3335 TotalRevolutions += RPS * Time . deltaTime ; // Scale by time since the last frame and add to the total revolutions
34- TotalTicks = ( int ) ( TotalRevolutions * TicksPerRevolution ) ; // Compute ticks of the encoder
35- TotalAngle = ( ( TotalTicks * 2 * Mathf . PI ) / TicksPerRevolution ) ; // Angle turned by the wheel (rad)
36+ TotalTicks = ( int ) ( TotalRevolutions * PPR * GearRatio ) ; // Compute ticks of the encoder
37+ TotalAngle = ( ( TotalTicks * 2 * Mathf . PI ) / ( PPR * GearRatio ) ) ; // Angle turned by the wheel (rad)
3638 //Debug.Log("Encoder Ticks: "+TotalTicks);
3739 //Debug.Log("Wheel Angle: "+TotalAngle);
3840 }
Original file line number Diff line number Diff line change @@ -123,7 +123,7 @@ PlayerSettings:
123123 16:10 : 0
124124 16:9 : 1
125125 Others : 0
126- bundleVersion : 0.1.0
126+ bundleVersion : 0.1.1
127127 preloadedAssets : []
128128 metroInputSource : 0
129129 wsaTransparentSwapchain : 0
You can’t perform that action at this time.
0 commit comments