void Update() { _planet = FindClosestPlanet(); Vector3 localPosition = _planet.ConvertToLocalPosition(_host.position); float dt = Time.deltaTime; Vector3 deltaPosition = _currentVelocity * dt; deltaPosition += _planet.GetGravity(localPosition) * _gravityFactor * dt; Vector3 targetLocalPosition = localPosition + deltaPosition; //CheckCollisions(_host.transform.position, deltaPosition, ref targetLocalPosition, ref _currentVelocity); Vector3 fixedPosition; if (SetOverTheSuface(targetLocalPosition, out fixedPosition)) { Vector3 diff = fixedPosition - localPosition; Vector3 forwardDelta = Vector3.Dot(diff, _host.forward) * _host.forward; Vector3 rightDelta = Vector3.Dot(diff, _host.right) * _host.right; Vector3 upDelta = Vector3.Dot(diff, _host.up) * _host.up; upDelta = Vector3.Slerp(Vector3.zero, upDelta, Time.deltaTime * 16f); Vector3 nextPosition = localPosition + forwardDelta + rightDelta + upDelta; _host.transform.position = nextPosition; } else { _host.transform.position = _planet.ConvertToWorldPosition(targetLocalPosition); } UpdateOrientation(); ApplyDrag(); }
void Update() { _planet = FindClosestPlanet(); Vector3 localPosition = _planet.ConvertToLocalPosition(_host.position); float dt = Time.deltaTime; Vector3 deltaPosition = _currentVelocity * dt; deltaPosition += _planet.GetGravity(localPosition) * _gravityFactor * dt; Vector3 targetLocalPosition = localPosition + deltaPosition; //CheckCollisions(_host.transform.position, deltaPosition, ref targetLocalPosition, ref _currentVelocity); Vector3 fixedPosition; if(SetOverTheSuface(targetLocalPosition, out fixedPosition)) { Vector3 diff = fixedPosition - localPosition; Vector3 forwardDelta = Vector3.Dot(diff, _host.forward) * _host.forward; Vector3 rightDelta = Vector3.Dot(diff, _host.right) * _host.right; Vector3 upDelta = Vector3.Dot(diff, _host.up) * _host.up; upDelta = Vector3.Slerp(Vector3.zero, upDelta, Time.deltaTime * 16f); Vector3 nextPosition = localPosition + forwardDelta + rightDelta + upDelta; _host.transform.position = nextPosition; } else { _host.transform.position = _planet.ConvertToWorldPosition(targetLocalPosition); } UpdateOrientation(); ApplyDrag(); }