- Home /
Cube roll over hills/objects
Today I am requesting aide in search of a solution to a problem I have been working on solving for the past few weeks. The problem is that the player will clip through any hills and fall through the map. The movement script only works on perfectly flat land, and this is not ideal. The player can also not jump until they have completely stopped moving, which is also not ideal. You can see the look of the animation that I have achieved here, and my code here. I started by using just physics, and that resulted in a movement hard to explain, which did not look nice. An example of that can be found here.
Any help is appreciated, thank you!
Answer by hexagonius · Jun 01, 2017 at 10:41 AM
The cube is basically just slipping. Check it's collider and the PhysicsMaterial slot. When you create one, assign it there and set it to maximum friction, it shouldn't slip anymore
Thanks, but I have already tried doing this. I should have specified further why this method would not work. I need a very precise roll. It must move one length of the cube at a time, and using friction and built in physics this is nearly impossible. I'm more looking for a way of calculating a shorter rotation based on the slope of any object in front of the cube. Thanks anyways!
Then you should study trigonometry, because that's going to be very complicated math.
Answer by Out_Of_Names · Jun 18, 2017 at 06:47 AM
Directly setting transform.position
will ignore physics and physics collisions. You may want to look at using a physics-based solution with a method such as AddTorque()
or AddForceAtPosition()
.