Question by
pstarhu · May 05, 2020 at 12:43 PM ·
gravitysphericalhovercraft
Hovercraft with spherical gravity
Hi!
I working on a planet game, and i can not solve a problem, a work with a spherical gravity which pull down rigidbody to the planet:
public float gravity = -9.8f;
public void Attract(Rigidbody body, string gravityBodyName)
{
Vector3 gravityUp = (body.position - transform.position).normalized;
body.AddForce(gravityUp * gravity, ForceMode.Acceleration);
}
And i have a hovercraft gravity script:
Ray ray = new Ray(transform.position, -transform.up);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, hoverHeight))
{
float proportionalHeight = (hoverHeight - hit.distance) / hoverHeight;
appliedHoverForce = transform.up * proportionalHeight * hoverForce;
if (addForce) carRigidbody.AddRelativeForce(appliedHoverForce);
}
How can I merge these two force to be one?
Now if i stop the hovercraft, then it start to go back by itself... :/
Comment
Your answer
Follow this Question
Related Questions
Changing gravity at the click of a button... 5 Answers
simple roll a ball game - ball slips threw ground 1 Answer
Spheres change form on collision 0 Answers
How to make GameObject fall with the same gravity while using AddForce() 1 Answer
[Kudan AR] (Markerless) Augmented Reality and Rigidbodies 0 Answers