The main character of a platform game I am working on is a sphere. The only control the player has over their sphere is moving to the left or right which works fine right now. I am using a Transform.Translate function to move the ball forward at a constant speed, but because it rotates along the z axis it pushing towards the ground for part of each rotation and digs itself into the terrain and literally gets stuck. I’ve tried several different fixes, but none of them have worked. Any ideas?
I think we would need to know more about your situation and the code you are using. I’m assuming you are using Unity physics (you have a Character Controller or a RigidBody on your sphere and are colliding against a Terrain?)
The most common reason for getting ‘stuck’ like this is that you have use Translate and thrown yourself ‘into’ the terrain.
Rather than using the normal translation functions, try using a CharacterMotor.
Check the code for the FPS controller and some of it’s friends - you’ll notice one spot where it has a line like this…
The CharacterMotor class knows all about avoiding collisions, sliding and avoiding terrain. By applying your user input to this rather than calling Translate, you’ll give the CharacterMotor the chance to say ‘No - That Will Get Me Stuck’. Instead, it will properly avoid terrain, slide down steep portions and will simulate physical properties like mass and inertia.
So if you were wanting to move your ball ‘left’ in response to a button press, you would say…
motor.inputMoveDirection = new Vector3(1,0,0);
Of course, you may need to change the axis I’ve shown here depending on how your scene is set up. Take a look at the FPS Controller for more ideas, since it shows you a pretty basic example of how to make it work.