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,21 +126,24 @@ public class PlayerController : MonoBehaviour
if (!isCriticalTackle) if (!isCriticalTackle)
{ {
// Add drag // Add drag
Vector3 dragDecceleration = DragDecceleration(currentVelocity, zone); if (zone == Zone.NimbleZone)
body.AddForce(dragDecceleration, ForceMode.Acceleration);
if (!isTackled)
{ {
// Add anti drift acceleration Vector3 dragDecceleration = DragDecceleration(currentVelocity, zone);
Vector3 driftDampeningAcceleration = DriftDampeningAcceleration(currentVelocity, zone); body.AddForce(dragDecceleration, ForceMode.Acceleration);
body.AddForce(driftDampeningAcceleration, ForceMode.Acceleration);
if (!isTackled)
{
// Add anti drift acceleration
Vector3 driftDampeningAcceleration = DriftDampeningAcceleration(currentVelocity, zone);
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 driftVelocity = currentVelocity - Vector3.Project(currentVelocity, rotation);
Vector3 rotation = transform.rotation.eulerAngles; antiDriftVelocity = Vector3.Reflect(-driftVelocity, transform.up) - driftVelocity;
Vector3 driftVelocity = currentVelocity - Vector3.Project(currentVelocity, rotation); antiDriftFactor = Mathf.InverseLerp(absolutMaxVelocity, normalMaxVelocity, currentVelocity.magnitude);
antiDriftVelocity = Vector3.Reflect(-driftVelocity, transform.up) - driftVelocity; antiDriftFactor = Mathf.Max(antiDriftFactor, minAntiDriftFactor);
antiDriftFactor = Mathf.InverseLerp(absolutMaxVelocity, normalMaxVelocity, currentVelocity.magnitude); Debug.DrawRay(transform.position, driftVelocity.normalized * 5, Color.red);
antiDriftFactor = Mathf.Max(antiDriftFactor, minAntiDriftFactor);
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;
} }