feat: Thrusting when player is turning (just for testing)

This commit is contained in:
Jakob Feldmann 2024-02-15 14:07:45 +01:00
parent 5fb14fb487
commit a840405379

View File

@ -1,4 +1,5 @@
using System; using System;
using Unity.Mathematics;
using UnityEngine; using UnityEngine;
using UnityEngine.InputSystem; using UnityEngine.InputSystem;
using UnityEngine.SceneManagement; using UnityEngine.SceneManagement;
@ -112,10 +113,11 @@ public class PlayerController : MonoBehaviour
currentGravity = forceManager.GetGravityForInstance(instanceID)(transform.position); currentGravity = forceManager.GetGravityForInstance(instanceID)(transform.position);
body.AddForce(currentGravity, ForceMode.Acceleration); body.AddForce(currentGravity, ForceMode.Acceleration);
float tackleFactor = isCriticalTackle ? stunLooseControlFactor : 1f; float stunFactor = isCriticalTackle ? stunLooseControlFactor : 1f;
Vector3 acceleration = thrustAcceleration * math.max(currentThrustInput - math.abs(currentSteerInput), math.abs(currentSteerInput))
* Time.deltaTime * Vector3.up * stunFactor;
Vector3 acceleration = thrustAcceleration * currentThrustInput * Time.deltaTime
* Vector3.up * tackleFactor;
Vector3 currentVelocity = body.velocity; Vector3 currentVelocity = body.velocity;
@ -124,6 +126,8 @@ public class PlayerController : MonoBehaviour
if (!isCriticalTackle) if (!isCriticalTackle)
{ {
// Add drag // Add drag
if (zone == Zone.NimbleZone)
{
Vector3 dragDecceleration = DragDecceleration(currentVelocity, zone); Vector3 dragDecceleration = DragDecceleration(currentVelocity, zone);
body.AddForce(dragDecceleration, ForceMode.Acceleration); body.AddForce(dragDecceleration, ForceMode.Acceleration);
@ -133,12 +137,13 @@ public class PlayerController : MonoBehaviour
Vector3 driftDampeningAcceleration = DriftDampeningAcceleration(currentVelocity, zone); Vector3 driftDampeningAcceleration = DriftDampeningAcceleration(currentVelocity, zone);
body.AddForce(driftDampeningAcceleration, ForceMode.Acceleration); body.AddForce(driftDampeningAcceleration, ForceMode.Acceleration);
} }
}
if (currentVelocity.magnitude <= normalMaxVelocity || IsBoosting() || zone != Zone.NimbleZone) if (currentVelocity.magnitude <= normalMaxVelocity || IsBoosting() || zone != Zone.NimbleZone)
{ {
body.AddRelativeForce(boostedAcceleration, ForceMode.Acceleration); body.AddRelativeForce(boostedAcceleration, ForceMode.Acceleration);
} }
if (currentVelocity.magnitude >= absolutMaxVelocity) if (currentVelocity.magnitude >= absolutMaxVelocity && zone == Zone.NimbleZone)
{ {
body.velocity = body.velocity.normalized * absolutMaxVelocity; body.velocity = body.velocity.normalized * absolutMaxVelocity;
} }
@ -152,18 +157,15 @@ public class PlayerController : MonoBehaviour
Vector3 DriftDampeningAcceleration(Vector3 currentVelocity, Zone zone) Vector3 DriftDampeningAcceleration(Vector3 currentVelocity, Zone zone)
{ {
Vector3 antiDriftVelocity = new Vector3(); Vector3 antiDriftVelocity;
float antiDriftFactor = 1f; float antiDriftFactor;
// Cancel out inertia/drifting // Cancel out inertia/drifting
if (zone == Zone.NimbleZone)
{
Vector3 rotation = transform.rotation.eulerAngles; Vector3 rotation = transform.rotation.eulerAngles;
Vector3 driftVelocity = currentVelocity - Vector3.Project(currentVelocity, rotation); Vector3 driftVelocity = currentVelocity - Vector3.Project(currentVelocity, rotation);
antiDriftVelocity = Vector3.Reflect(-driftVelocity, transform.up) - driftVelocity; antiDriftVelocity = Vector3.Reflect(-driftVelocity, transform.up) - driftVelocity;
antiDriftFactor = Mathf.InverseLerp(absolutMaxVelocity, normalMaxVelocity, currentVelocity.magnitude); antiDriftFactor = Mathf.InverseLerp(absolutMaxVelocity, normalMaxVelocity, currentVelocity.magnitude);
antiDriftFactor = Mathf.Max(antiDriftFactor, minAntiDriftFactor); antiDriftFactor = Mathf.Max(antiDriftFactor, minAntiDriftFactor);
Debug.DrawRay(transform.position, driftVelocity.normalized * 5, Color.red); Debug.DrawRay(transform.position, driftVelocity.normalized * 5, Color.red);
}
Debug.DrawRay(transform.position, antiDriftVelocity.normalized * 5, Color.green); Debug.DrawRay(transform.position, antiDriftVelocity.normalized * 5, Color.green);
return antiDriftVelocity * antiDriftAmount * antiDriftFactor; return antiDriftVelocity * antiDriftAmount * antiDriftFactor;
} }