done
This commit is contained in:
parent
3a7ce962e7
commit
058e61a4fd
38 changed files with 3915 additions and 363 deletions
|
@ -2,8 +2,12 @@ using UnityEngine;
|
|||
|
||||
public class Boost : MonoBehaviour
|
||||
{
|
||||
[SerializeField] Rigidbody rb;
|
||||
[SerializeField] float boostMultiplier;
|
||||
[SerializeField] Rigidbody _rb;
|
||||
[SerializeField] float boostForce;
|
||||
[SerializeField] float boostRefillTime;
|
||||
|
||||
[HideInInspector]
|
||||
public float charge { get; private set; } // Beetwen 0 and 1
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
|
@ -14,10 +18,13 @@ public class Boost : MonoBehaviour
|
|||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
// Middle click
|
||||
if (Input.GetMouseButton(2))
|
||||
|
||||
charge = Mathf.Clamp(charge + Time.deltaTime / boostRefillTime, 0, 1.0f);
|
||||
// Middle click and 0.99f because I'm affraid of floating point comparison
|
||||
if (Input.GetMouseButton(2) && charge >= 0.99f)
|
||||
{
|
||||
rb.linearVelocity *= boostMultiplier;
|
||||
_rb.AddForce(boostForce * _rb.transform.forward, ForceMode.Impulse);
|
||||
charge = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
37
TP3/Assets/Scripts/CarThings/CheckpointCheck.cs
Normal file
37
TP3/Assets/Scripts/CarThings/CheckpointCheck.cs
Normal file
|
@ -0,0 +1,37 @@
|
|||
using UnityEngine;
|
||||
|
||||
public class CheckpointCheck : MonoBehaviour
|
||||
{
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
|
||||
public const int MAX_LAPS = 3;
|
||||
[HideInInspector] public int NumberOfLaps { get; private set; } = 0;
|
||||
|
||||
private int currentCheckPointIndex = 0;
|
||||
private int numberOfCheckpoints;
|
||||
void Start()
|
||||
{
|
||||
numberOfCheckpoints = Object.FindObjectsByType<Checkpoint>(FindObjectsSortMode.None).Length;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void OnTriggerEnter(Collider collision)
|
||||
{
|
||||
print("Collision");
|
||||
if (!collision.gameObject.TryGetComponent(out Checkpoint checkpoint)) return;
|
||||
|
||||
if (checkpoint.Index == currentCheckPointIndex) currentCheckPointIndex++;
|
||||
|
||||
if (currentCheckPointIndex == numberOfCheckpoints)
|
||||
{
|
||||
currentCheckPointIndex = 0;
|
||||
NumberOfLaps++;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
2
TP3/Assets/Scripts/CarThings/CheckpointCheck.cs.meta
Normal file
2
TP3/Assets/Scripts/CarThings/CheckpointCheck.cs.meta
Normal file
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3ccd479800bf10341b6e8ffa6bff8e33
|
50
TP3/Assets/Scripts/CarThings/Drift.cs
Normal file
50
TP3/Assets/Scripts/CarThings/Drift.cs
Normal file
|
@ -0,0 +1,50 @@
|
|||
using UnityEngine;
|
||||
|
||||
public class Drift : MonoBehaviour
|
||||
{
|
||||
[SerializeField] Rigidbody rb;
|
||||
[SerializeField] private float baseLateralFrictionCoeff = 5f;
|
||||
[SerializeField] private float lateralVelocityStartDriftThreshold = 10f;
|
||||
[SerializeField] private float lateralVelocityTotalDriftThreshold = 15f;
|
||||
|
||||
[SerializeField] private TrailRenderer trailRendererLeft;
|
||||
[SerializeField] private TrailRenderer trailRendererRight;
|
||||
|
||||
|
||||
[SerializeField] RotateWithMouse moreRotateWhenDrift;
|
||||
|
||||
[SerializeField] [Range(1, 5)] float RotateLerpSpeedMultipler;
|
||||
|
||||
private float lateralFrictionCoeff;
|
||||
private float baseRotateLerpSpeed;
|
||||
private float newRotateLerpSpeed => baseRotateLerpSpeed * RotateLerpSpeedMultipler;
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
baseRotateLerpSpeed = moreRotateWhenDrift.lerpSpeed;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void FixedUpdate()
|
||||
{
|
||||
|
||||
|
||||
Vector3 forwardVelocity = Vector3.Project(rb.linearVelocity, transform.forward);
|
||||
Vector3 lateralVelocity = rb.linearVelocity - forwardVelocity;
|
||||
|
||||
// dynamicCoeff is equal to 1 when no drift is happening, and 0 when the drift is at its maximum
|
||||
float dynamicCoeff = Mathf.InverseLerp(lateralVelocityTotalDriftThreshold, lateralVelocityStartDriftThreshold, lateralVelocity.magnitude);
|
||||
trailRendererLeft.emitting = dynamicCoeff < 0.9f;
|
||||
trailRendererRight.emitting = dynamicCoeff < 0.9f;
|
||||
|
||||
|
||||
// When no drift -> lerpSpeed = baseRotateLerpSpeed, when drift -> lerpSpeed = newRotateLerpSpeed
|
||||
moreRotateWhenDrift.lerpSpeed = Mathf.Lerp(newRotateLerpSpeed, baseRotateLerpSpeed, dynamicCoeff);
|
||||
lateralFrictionCoeff = baseLateralFrictionCoeff * dynamicCoeff;
|
||||
print(dynamicCoeff);
|
||||
|
||||
Vector3 lateralFrictionForce = -lateralVelocity * lateralFrictionCoeff;
|
||||
rb.AddForce(lateralFrictionForce, ForceMode.Acceleration);
|
||||
}
|
||||
|
||||
}
|
2
TP3/Assets/Scripts/CarThings/Drift.cs.meta
Normal file
2
TP3/Assets/Scripts/CarThings/Drift.cs.meta
Normal file
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 126ace550d661844b89827d37837767f
|
|
@ -4,9 +4,9 @@ public class RotateWithMouse : MonoBehaviour
|
|||
{
|
||||
[SerializeField] LayerMask layerToIgnore;
|
||||
[SerializeField] Transform targetTransform;
|
||||
[SerializeField]
|
||||
|
||||
[Range(0f, 1f)]
|
||||
float lerpSpeed = 0.1f;
|
||||
public float lerpSpeed = 0.01f;
|
||||
|
||||
Rigidbody rb;
|
||||
Camera cam;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue