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 Unity.Mathematics;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.SceneManagement;
@ -112,10 +113,11 @@ public class PlayerController : MonoBehaviour
currentGravity = forceManager.GetGravityForInstance(instanceID)(transform.position);
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;
@ -124,21 +126,24 @@ public class PlayerController : MonoBehaviour
if (!isCriticalTackle)
{
// Add drag
Vector3 dragDecceleration = DragDecceleration(currentVelocity, zone);
body.AddForce(dragDecceleration, ForceMode.Acceleration);
if (!isTackled)
if (zone == Zone.NimbleZone)
{
// Add anti drift acceleration
Vector3 driftDampeningAcceleration = DriftDampeningAcceleration(currentVelocity, zone);
body.AddForce(driftDampeningAcceleration, ForceMode.Acceleration);
Vector3 dragDecceleration = DragDecceleration(currentVelocity, zone);
body.AddForce(dragDecceleration, 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)
{
body.AddRelativeForce(boostedAcceleration, ForceMode.Acceleration);
}
if (currentVelocity.magnitude >= absolutMaxVelocity)
if (currentVelocity.magnitude >= absolutMaxVelocity && zone == Zone.NimbleZone)
{
body.velocity = body.velocity.normalized * absolutMaxVelocity;
}
@ -152,18 +157,15 @@ public class PlayerController : MonoBehaviour
Vector3 DriftDampeningAcceleration(Vector3 currentVelocity, Zone zone)
{
Vector3 antiDriftVelocity = new Vector3();
float antiDriftFactor = 1f;
Vector3 antiDriftVelocity;
float antiDriftFactor;
// Cancel out inertia/drifting
if (zone == Zone.NimbleZone)
{
Vector3 rotation = transform.rotation.eulerAngles;
Vector3 driftVelocity = currentVelocity - Vector3.Project(currentVelocity, rotation);
antiDriftVelocity = Vector3.Reflect(-driftVelocity, transform.up) - driftVelocity;
antiDriftFactor = Mathf.InverseLerp(absolutMaxVelocity, normalMaxVelocity, currentVelocity.magnitude);
antiDriftFactor = Mathf.Max(antiDriftFactor, minAntiDriftFactor);
Debug.DrawRay(transform.position, driftVelocity.normalized * 5, Color.red);
}
Vector3 rotation = transform.rotation.eulerAngles;
Vector3 driftVelocity = currentVelocity - Vector3.Project(currentVelocity, rotation);
antiDriftVelocity = Vector3.Reflect(-driftVelocity, transform.up) - driftVelocity;
antiDriftFactor = Mathf.InverseLerp(absolutMaxVelocity, normalMaxVelocity, currentVelocity.magnitude);
antiDriftFactor = Mathf.Max(antiDriftFactor, minAntiDriftFactor);
Debug.DrawRay(transform.position, driftVelocity.normalized * 5, Color.red);
Debug.DrawRay(transform.position, antiDriftVelocity.normalized * 5, Color.green);
return antiDriftVelocity * antiDriftAmount * antiDriftFactor;
}