- Home /
How to simulate moon gravity?
Hello! For 7DFPS I'm making a game where you are an astronaut exploring a moon, but I have a problem. I need to have gravity which centers around the moon, which is a sphere. I've looked at a lot of similar questions, but none of them work for me! Just a heads up, I'm using the first person controller. Do any of you know how to achieve?
each frame, simply add a force pointing towards the middle of the planetoid.
Answer by Youngdeveloper · Jun 11, 2012 at 06:09 PM
In your used "First Person Controller" in Inspector, go to Character Motor(Script) -->Movement and change Max Ground Accelaration to 15, Max Air Acceleration to, lets say 4, also Gravity to 10 and Max Fall Speed to 2. Now you jump and fall slowly, just like on moon.
Answer by Youngdeveloper · Jun 11, 2012 at 06:10 PM
Hi, lowering the options like gravity for your fps moving capsule could be the option ( if your using default mesh).
Answer by Setzer22 · Jun 11, 2012 at 05:19 PM
Well, acoording Newton's gravitation law, this can be simplified to a force acting on your character, assuming the force vector should always point to the planet's (in your case, the moon's) gravity center, so the sphere center (the moon's gameObject transform.position). So you just have to apply a force on your character, and rotate the force vector so it always looks at the center of the moon.
Also, you cannot work with forces if you aren't on a rigidbody. If you're using the FPS controller, I assume you are using a character controller. This can be easily fixed, as forces are proportional to the acceleration they provoke, so accelerating your character towards the center of the moon should do that same effect. Just some easy physics.
Here's a little bit of pseudo-coding of what I'm talking about:
define a Vector3 variable called acceleration;
Update function (){
acceleration = Vector3(0,0,gravity);
make acceleration look at the center of the moon
transform.position += acceleration*time.deltaTime
}
That should do it. Actually, I don't remember if there's a function to make a vector "look" to a given point, but there should be one, if not, you've got the transform.lookAt() method, then you could use that transform's forward vector to give a direction to your acceleration.
EDIT: Check out the Vector3.RotateTowards() method, I don't know if it's what you're looking for, else you'll have to work with a transform instead of a vector3 in order to use transform.lookAt()
Thanks! I hope I'm not asking to much, but if you do know how to make this script in either Javascript or C#, could you post that? I'm trying to figure it out on my own but I'm having kind of a hard time and I'm on a tight schedule! Just tried, it isn't working. EDIT: Can't find any documentation on how to use rotatetorwards!
Sorry, can't do it atm, I've got my finals tomorrow so I need to study hard :/
Your answer
Follow this Question
Related Questions
Planet gravity help need guidance no code 1 Answer
Multiple Planets with their own gravitational pull 1 Answer
Adding a force(gravity) to a planet. 0 Answers
Planetary physics for player 1 Answer
Planetary based gravity 0 Answers