private void ApplyHover(HoverInput hoverInput) { var ray = new Ray(CachedTransform.position, -CachedTransform.up); RaycastHit hit; if (Physics.Raycast(ray, out hit, hoverHeight)) { var force = _defaultForce + ((hoverHeight - hit.distance) / hoverHeight * correctiveForce); CachedRigidbody.AddForce(Vector3.up * force, ForceMode.Force); } CachedRigidbody.AddRelativeForce(0f, 0f, hoverInput.vertical * speed, ForceMode.Acceleration); if (strafe) { CachedRigidbody.AddRelativeForce(hoverInput.horizontal * speed, 0f, 0f, ForceMode.Acceleration); } else { CachedRigidbody.AddRelativeTorque(0f, hoverInput.horizontal * turnSensitivity, 0f, ForceMode.Acceleration); } if (hoverInput.jump) { CachedRigidbody.AddForce(Vector3.up * jumpStrength, ForceMode.Acceleration); } }
protected override void OnStart() { base.OnStart(); if (CachedRigidbody == null) { CachedRigidbody = gameObject.AddComponent <Rigidbody>(); } CachedRigidbody.AddRelativeForce(new Vector3(0f, 0f, _forwardForce)); }