- Home /
Question too broad
How to make one object pull another (gravity)?
Hey, I was searching for some planetary gravity sctipts, but any of this what i found didnt work... So once again I need help. All what i want to do is to make one object pull a player. The game is about flying simple rocket what use rigidbody to move, and I want to make it able to orbit arround not big sphere. If it is possible i wish it was a java script and kinda simple (i only hope it will be simple, because pulling one object to another sounds easy) Sorry for my bad english! :/
Ins$$anonymous$$d of saying "I need help!" How about you post the code, that "does not work" and we can work through fixing it.
As of now, the only answer you will get is: Apply force to the object using the gravitational force formula
Google "unity3d planetary gravity," and do some research. There are multiple approaches, and a number of interesting posts in UA on this question. As it stands now, your question is too broad for an answer, plus UA is about helping you solve your own problem, not writing a script for you. If in researching this issue you have specific technical issues, we welcome a new, focused question.
Well, I know it's already closed, but quite a time ago i found a solution: var Planet : GameObject; var force : float = -0.1;
function Update ()
{
rigidbody.AddForce ((transform.position - planet.transform.position).normalized * force * rigidbody.mass, Force$$anonymous$$ode.Impulse);
}
Answer by pborg · Jul 18, 2013 at 06:59 AM
I worked on a game a few months ago that involved using orbit as at tool. Our team member in charge of creating the orbit physics did all sorts of research in applying forces. We ended up just setting the rocket to the child of the planet. All rotation and movement applied to the planet will cause the rocket to orbit around it and move with it respectively. Amazingly simple, just drag the rocket onto the planet in the editor or via script: //rocket script
var planet : Transform;
function Start()
{
//use find techniques to get the planet
transform.parent = planet;
}
I hope this helps. If you or anybody else wants to ask any other questions, or comment on something I missed, feel free!
No offence, but your $$anonymous$$m member must not be very good. It's quite easy finding the velocity needed to stay within orbit of a object with a gravitational field. It's all explained right here
But then again, rigidbody physics might be to inaccurate for a proper orbit ;)
Also your answer does not answer the question. The questions said: "implement gravity" not "make orbit", sorry, but I'm gonna have to give a -1
@$$anonymous$$roductions " and I want to make it able to orbit arround not big sphere. If it is possible i wish it was a java script and kinda simple"
Follow this Question
Related Questions
Adding a jump feature help? 2 Answers
how to add gravity to this script 2 Answers
How to change gravity direction on Character Motor 0 Answers
Gravity - How to walk on ceiling 1 Answer
3D Gravity towards one object 3 Answers