- Home /
How to make a continuous runner on a planet with gravity?
Hi, I am looking to create a continuous runner game around a planet and am having a hard time getting the player to continually move around the planet and adjust their direction/rotation to match when the left/right keys are input. Anything I have is pretty useless so far so have no code to post. Note I am quite new to Unity so apologies if this is a stupid question. Any help is appreciated. Thanks
Answer by Sherlore · Aug 09, 2016 at 09:02 AM
I guess one of below design may help you.
Design A: Runner actually doesn't move and rotate in scene. Make the planet and background rotate reversely, so that runner seem like running forward.
Design B: Runner actually run on the planet.
Runner's rotation always depend on vector (planet.position - runner.position)
//e.g. y-axis always match vector (planet.position - runner.position)
.
and for gravity
B-1: To make runner receive gravity, continuously change Physics.gravity to vector (planet.position - runner.position)
B-2: Don't use Physics.gravity. Set all object with rigidbody not use gravity. Create trigger for planet as gravity zone, when object inside trigger (onTriggerStay), use AddForce with direction (planet.position - object .position) to simulate gravity
Wish these could help you, good luck!!
I have gone more with option B above and managed to get part way to my goal. I have an object starting on top of a sphere and it begins to move in a direction at a constant speed. To work out where to go I am getting the direction it is facing, multiplying the speed to the vector to deter$$anonymous$$e the target position (directly ahead and off the sphere). I am then using a raycast to deter$$anonymous$$e where the hitpoint is on the sphere and lerping to that position.
Some issues i now have is all around rotating the object. How do I deter$$anonymous$$e how much to rotate the object between its current position and its target position? Vectors that I know include: current position current up (player position - planet position) current direction target position (based on horizontal input, movement speed, raycast hitpoint) target up (target position - planet position)
Your answer
Follow this Question
Related Questions
how to apply orbit to the player 2 Answers
Implementing FPS view into locomotion planet walk 1 Answer
how to make gravity in the center of a sphere 1 Answer
Adding a force(gravity) to a planet. 0 Answers