// 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);
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter