Collectives on Stack Overflow. Learn more. Asked 9 years, 7 months ago. Active 9 years, 7 months ago. Viewed 13k times. Using Unity 3.
Log "i hit it!!! Improve this question. Add a comment. Active Oldest Votes. Improve this answer. Shredder Shredder 1, 2 2 gold badges 11 11 silver badges 25 25 bronze badges.
I actually need it to stick once it reachs the surface but not be fixed position — lemunk. In fact, I'm currently working on a game based around gravity: simply, you place stars to move your player through eliptical orbits and the slingshot effect.
I disabled gravity, and used this code:. PS The code originally looped through an array of all the planets: this is edited and therefore may not be fully correct. It should be okay though.
There's no need to resort to the gravitational equation. Acceleration due to gravity is constant regardless of mass, so all you want to do is accelerate your small objects towards the large-object each frame.
I've been working on a similar project based in Zero-G in which I need all game objects to generate and react to both gravitational and electromagnetic force based on their volume, density, mass, energy and conductivity. I'm relatively new to scripting, but I've made a few modifications to the script above to make it work for me in a 3D space as far as gravity is concerned As you can see, I'm still working on it, basically all my additions so far, annotated with "BBB", aren't yet functioning as I'd like.
Now, the planet should either be tagged planet or static cosmic object, and the child should be labeled Area of influence. Now the small object should have a rigidbody and a sphere with a isTrigger. Else you can do it the other way around. But in any case this would probably be better since you most likely want to make gravitational pull different from planet to planet. What others said, gravity on unity is only towards a certain direction, so maybe you should instead disable gravity completly and script a force that moves the small sphere towards the huge one.
GetComponent is in Update, because i want to make possibility to change rotation this plane in game. Sign up to join this community. The best answers are voted up and rise to the top. Stack Overflow for Teams — Collaborate and share knowledge with a private group.
Create a free Team What is Teams? Learn more. How to change Gravity towards certain object in Unity? Anyone knows what formula Unity uses for gravity? To be more specific, I have a rigidbody on the floor. I want to rigidbody.
AddForce Vector3. I hope not, since if the object is heavy, you would need more force to lift it than if it is lighter.
Anyone knows what's the break-even formula where if you apply X Vector3. Joined: Oct 8, Posts: I have a related question, but first let me respond. In my example, if I did rigidbody. I imagine you need to do it every FixedUpdate to make it work didn't check that. I noticed that if you set the parameter mode to ForceMode. Impulse , it will have the effect you describe. The docs say this about the forces: - ForceMode.
Force : acceleration, depends on mass, call in FixedUpdate - ForceMode. VelocityChange : changes the velocity, undependant of mass, doesn't say if you call it once or have to keep calling it, but my bet is you call it only once - ForceMode.
Acceleration : same as force, but ignores mass - ForceMode. Impulse : changes the velocity, depends on mass, I found out you should only call this once, otherwise your object will quite quickly reach absurd speeds As for my related question, I couldn't figure out how to change the fall speed of an rigidobject.
0コメント