Skip to content

Commit

Permalink
feat: Refactoring to simplify
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Several API changes. Version 2.x starts
  • Loading branch information
Vatsal Ambastha committed Apr 18, 2020
1 parent 0373497 commit e6752cb
Show file tree
Hide file tree
Showing 27 changed files with 341 additions and 3,841 deletions.
4 changes: 2 additions & 2 deletions .releaserc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
"@semantic-release/release-notes-generator",
["@semantic-release/changelog", {
"preset": "angular",
"changelogFile":"Assets/Adrenak.Tork/CHANGELOG.MD"
"changelogFile":"Assets/Adrenak.Tork/CHANGELOG.md"
}],
["@semantic-release/npm", {
"npmPublish": false,
"pkgRoot":"Assets/Adrenak.Tork"
}],
["@semantic-release/git", {
"assets": ["Assets/Adrenak.Tork/package.json", "Assets/Adrenak.Tork/CHANGELOG.md"],
"assets": ["Assets/Adrenak.Tork/package.json", "Assets/Adrenak.Tork/CHANGELOG.md", "CHANGELOG.md"],
"message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
}],
"@semantic-release/github"
Expand Down
16 changes: 0 additions & 16 deletions Assets/Adrenak.Tork/Editor/Adrenak.Tork.Editor.asmdef

This file was deleted.

14 changes: 0 additions & 14 deletions Assets/Adrenak.Tork/Editor/CenterOfMassAssignerDebug.cs

This file was deleted.

11 changes: 0 additions & 11 deletions Assets/Adrenak.Tork/Editor/CenterOfMassAssignerDebug.cs.meta

This file was deleted.

21 changes: 0 additions & 21 deletions Assets/Adrenak.Tork/Editor/WheelDebug.cs

This file was deleted.

8 changes: 0 additions & 8 deletions Assets/Adrenak.Tork/Runtime/Input/Driver.cs

This file was deleted.

5 changes: 5 additions & 0 deletions Assets/Adrenak.Tork/Runtime/Input/IVehicleDriver.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace Adrenak.Tork {
public interface IVehicleDriver {
VehicleInput GetInput();
}
}
16 changes: 0 additions & 16 deletions Assets/Adrenak.Tork/Runtime/Input/KeyboardDriver.cs

This file was deleted.

17 changes: 17 additions & 0 deletions Assets/Adrenak.Tork/Runtime/Input/KeyboardVehicleDriver.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using UnityEngine;

namespace Adrenak.Tork{
public class KeyboardVehicleDriver : IVehicleDriver {
public const string k_SteeringAxisName = "Horizontal";
public const string k_AccelerateAxisName = "Vertical";
public const string k_BrakeAxisName = "Jump";

public VehicleInput GetInput() {
return new VehicleInput {
acceleration = Input.GetAxis(k_AccelerateAxisName),
steering = Input.GetAxis(k_SteeringAxisName),
brake = Input.GetAxis(k_BrakeAxisName)
};
}
}
}
36 changes: 20 additions & 16 deletions Assets/Adrenak.Tork/Runtime/Mechanics/Vehicle.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
using UnityEngine;

namespace Adrenak.Tork {
public class Vehicle : MonoBehaviour {
[SerializeField] VehicleDriver m_Player;
public class Vehicle : MonoBehaviour {
readonly IVehicleDriver defaultDriver = new KeyboardVehicleDriver();
IVehicleDriver driver;
public IVehicleDriver Driver {
get { return driver = driver ?? defaultDriver; }
set { driver = value ?? defaultDriver; }
}

public Steering m_Steering;
public Motor m_Motor;
public Brakes m_Brake;
[SerializeField] Steering steering;
public Steering Steer { get { return steering; } }

public void SetPlayer(VehicleDriver player) {
m_Player = player;
}
[SerializeField] Motor motor;
public Motor Motor { get { return motor; } }

void Update() {
if (m_Player == null) return;
[SerializeField] Brakes brake;
public Brakes Brake { get { return brake; } }

var input = m_Player.GetInput();
void Update() {
var input = Driver.GetInput();

m_Steering.value = input.steering;
m_Motor.value = input.acceleration;
m_Brake.value = input.brake;
}
}
steering.value = input.steering;
motor.value = input.acceleration;
brake.value = input.brake;
}
}
}
4 changes: 0 additions & 4 deletions Assets/Adrenak.Tork/Runtime/Mechanics/WheelRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ public class WheelRenderer : MonoBehaviour {
public float offset;
public float angle;

private void OnValidate() {
SyncPosition();
}

public void Update() {
SyncPosition();
SyncRotation();
Expand Down
20 changes: 7 additions & 13 deletions Assets/Adrenak.Tork/Runtime/Physics/Wheel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ public class Wheel : MonoBehaviour {
/// </summary>
public float stiffness = 10000;

[Tooltip("Damping applied to the wheel. Lower values make the wheel bounce more.")]
[Tooltip("Damping applied to the wheel. Higher values make the wheel bounce more. Values outside [0, 0.77f] tend to be unnatural")]
/// <summary>
/// Damping applied to the wheel. Lower values make the wheel bounce more.
/// Damping applied to the wheel. Higher values make the wheel bounce more. Values outside [0, 0.77f] tend to be unnatural
/// </summary>
public float damping = 5000;
public float dampingFactor = .5f;

[Tooltip("The rate (m/s) at which the spring relaxes to maximum length when the wheel is not on the ground.")]
/// <summary>
Expand All @@ -46,19 +46,13 @@ public class Wheel : MonoBehaviour {
/// </summary>
public float forwardGrip = 1;

[Tooltip("Multiplier for the wheels sideways friction. Values below 1 cause the wheel to skid. Values above 1 will cause the wheel to take sharper turns")]
[Tooltip("A constant friction % applied at all times. This allows the car to slow down when no torque is applied")]
/// <summary>
/// Multiplier for the wheels sideways friction Values below 1 cause the wheel to skid Values above 1 will cause the wheel to take sharper turns
/// A constant friction % applied at all times. This allows the car to slow down when no torque is applied
/// </summary>
public float rollingFriction = .1f;

[Header("Collision")]
[Tooltip("Whether the normal force from the wheel collision should be faked. True causes the force to be applied only along the wheels upward direction causing causing it to not slow down from collisions")]
/// <summary>
/// Whether the normal force from the wheel collision should be faked. True causes the force to be applied only along the wheels upward direction causing causing it to not slow down from collisions
/// </summary>
public bool fakeNormals;

[Header("Raycasting")]
/// <summary>
/// The layers used for wheel raycast
/// </summary>
Expand Down Expand Up @@ -176,7 +170,7 @@ public class Wheel : MonoBehaviour {
float rate = (m_PrevCompressionDist - CompressionDistance) / Time.fixedDeltaTime;
m_PrevCompressionDist = CompressionDistance;

float damperForce = rate * damping;
float damperForce = rate * stiffness * (1 - dampingFactor);
force -= damperForce;

force *= Vector3.Dot(Hit.normal, transform.up);
Expand Down

0 comments on commit e6752cb

Please sign in to comment.