- Home /
How do I stop my player from very slowly sinking into the ground?
I am trying to make an infinite runner and have already made the player and the infinite tile generation. Everything works, except there, is one problem, the player keeps falling little by little over time, even though they are supposed to be on the ground. Once the player sinks enough, they hit the tile of ground in front of them, causing them to fly into the air. How can I prevent the player from sinking into the ground tile so this problem will not happen?
Here is a video of it happening: https://streamable.com/vnbb3c
Answer by ahsen35813 · Jun 15, 2020 at 08:53 PM
From the video I noticed that the x angle of the player is 0.002 during playtime. Is this intentional? It may be the problem if you are using transform.setRelativePosition. However, if you are using forces to move your player, I cannot think what might be causing this issue.
I also noticed that, the x coordinate and y angle are increasing, and the z angle appears to be decreasing very slowly.
As for potential solutions, maybe try constraining the x rotation of the player and/or starting the game with the player at y 0.1 to make sure the player lands on top of the surface.
I am using forces to move my player so the problem is not with set.RelativePosition. However, you have alerted my attention to something very odd. When I try to change the player's rotation to (0,0,0) in the inspector, it changes back to (0.001,-0.002, 0.005). Also, when I start the player at a y level of 1.1 and let the player fall, the same issue happens. Freezing the x,y,z rotations of the player seems to fix the issue, but I need my player to be able to rotate in-game so this is not a good long term solution.
That is very strange. I hope you can fix the problem!
I found out this was occuring because my player spawned within a collider. Check if any mesh colliders especially are set to convex just to check if they are intersecting with your player.
Answer by s4shrish · Aug 26, 2020 at 07:45 PM
If it is what I think it is, it is NOT at all something related to your player sinking. This seems to me something that I even observed in my 2D game, that is sometimes the tile generation is a little bit rough, a VERY small number up and down, just like your player not being at EXACTLY 1.00000000000f value in Y-axis. And at high speed that SMALL bump in the road will make your player go FAR up in the sky. Happened in one of my 2D games, except he was moving horizontally and suddenly jumping despite not being programmed at all.
So to confirm my theory, change your Collider from a Box collider to a Capsule Collider, and limit the rotation of the RigidBody.
Your answer
Follow this Question
Related Questions
How do I connect multiple spheres using joints and make a character? 1 Answer
Shooting a cannonball. 6 Answers
Solar System Simulator Orbits Not Working 2 Answers
My object falls through terrain. 8 Answers
How may I observe expected physical interactions while using Rigidbody.MoveRotation()? 1 Answer