- Home /
How to make a ball that can roll?
In my game, the player is a first person controller. The player can also place soccer balls on the ground. I want it so then when the first person controller collides with the soccer balls, they will start to roll around. Is there any way I can do this?
Can't you simply apply sphere collider to the ball object?
If I add a sphere collider, the ball will just stay in the same spot, even if the first person controller collides with it.
Good. What about applying force at the normal direction of the hit as shown in the link given?
Answer by aldonaletto · Jul 26, 2013 at 03:18 AM
The CharacterController is just constrained by other colliders - it doesn't push anything. If you want to push rigidbodies, use OnControllerColliderHit to detect the collision and to apply a force or set the rigidbody velocity:
var force: float = 100;
function OnControllerColliderHit(hit: ControllerColliderHit){
if (hit.rigidbody){
var dir = hit.normal; // get the hit direction
dir.y = 0; // consider only the horizontal direction
hit.rigidbody.AddForce(force * dir.normalized);
}
}
Tweak the force in order to get better results. You may also set dir.y to a value between 0.1 and 0.5 to make the ball go a little up instead of strictly horizontal.
I forgot that there character controller does not move things by itself
Answer by Linus · Jul 26, 2013 at 02:16 AM
Sphere collider and rigidbody, you most likely want gravity activated. You might want to watch some tutorials or reading up on how unity works.
I have some experience in Unity and I was thinking about using a rigidbody. But when I added a rigidbody to the ball and tried making the first person controller collide with it, nothing happened. The ball just stopped the first person controller from moving forward. I change the physic material to bouncy, which helped a bit, just now the ball bounces too much. I hope I clarified the situation more.
Soccer ball require force to move. If the sphere does not move, perhaps your ball object is a lot heavier than the character object. Did you look at the hockey link I gave above?