Hello!
In my game I have a GameObject (called Ball) that has a RigidBody. I want to roll the ball over the ground. Unfortunately I assigned the floor a PhysicsMaterial with friction = 0 (which I cant change cause I already created 100+ levels).
Since the friction is 0 the ball only slides over the floor without any rotation. I want to fake the rotation as purely graphics effect. Therefore I added a childobject “BallGeometry” that holds the ball geometry (MeshRenderer).
I made a screenshot to show the hierarchy:
Currently the ball just slides forward along the forward axis (blue). To fake a rotation I now want to rotate the “BallGeometry” child object around its local Right-Axis (right arrow) based on the rigidbody’s velocity.
By only manipulating “BallGeometry” I don’t interfere with the physics of the RigidBody (which is placed on root “Ball”).
I tried this code:
float moveSpeed = rigidBody.velocity.magnitude;
if(moveSpeed > 0.001f) {
ballGeometryTransform.rotation = Quaternion.LookRotation(rigidBody.velocity);
}
With this code the ball is always aligned with its velocity (i.e. if the ball is pushed to the left, BallGeometry forward axis points to the left) but the ball is not spinning at all.
Does anyone know how I could extend to code to make the ball rotate around its local “right” axis based on the rigidbody’s velocity?
