Created
April 11, 2024 11:31
-
-
Save v0xel1337/d766fcd444b97a6856fa7de4d79380b7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Apply force - More up assist depending on y position | |
var assistPoint = Mathf.InverseLerp(0, _maxY, _rb.position.y); | |
var assistAmount = Mathf.Lerp(_maxUpAssist, 0, assistPoint); | |
var forceDir = -transform.forward * _forceAmount + Vector3.up * assistAmount; | |
if (_rb.position.y > _maxY) forceDir.y = Mathf.Min(0, forceDir.y); | |
_rb.AddForce(forceDir); | |
// Determine the additional torque to apply when swapping direction | |
var angularPoint = Mathf.InverseLerp(0, _maxAngularVelocity, Mathf.Abs(_rb.angularVelocity.z)); | |
var amount = Mathf.Lerp(0, _maxTorqueBonus, angularPoint); | |
var torque = _torque + amount; | |
// Apply torque | |
var dir = Vector3.Dot(_spawnPoint.forward, Vector3.right) < 0 ? Vector3.back : Vector3.forward; | |
_rb.AddTorque(dir * torque); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment