I have a small question for you. We’re working on a game in which the ball must behave in a realistic way : that means it should rebound correctly when hitting a wall or any other object.
The problem we have is that we want the ball to roll at a constant speed. We tried setting directly its velocity but we don’t like the result because the ball doesn’t bounce correctly. We also tried to use constantForce.force in a FixedUpdate but the ball was accelerating.
Is there any way to keep the physics working correctly and force the ball to keep its speed ?
When you override the velocity vector don’t change its direction. Simply scale its length to the appropriate speed. An quick and easy way to try this is to simply normalize the velocity vector and then scale the resulting unit length vector by your chosen speed and set that as the new balls velocity. This way, the physics system will still calculate the correct direction component of your velocity but you can just control its length / speed/.
Thanks ! It seems to be working. Now is there something like an AddForce that can be used with velocity ?
Because the AddForce doesn’t work. I’m guessing the velocity overrides the velocity changes made by the AddForce.
Well it was my understanding that you wanted the ball to roll at a constant speed in which case you are just using AddForce to get the ball rolling initially in the direction you want it to roll. If what you mean is you want the ball to be able to never exceed a certain speed then you can choose only clamp the ball velocity if it exceed the desired maximum velocity. If you really do want the ball to be a constant speed then by its very definition you are overriding what AddForce is intending to do…other than setting the balls direction.
Sorry if I have misunderstood your problem and if so can you elaborate or perhaps show your ball update code as it is atm.
I’m sorry, you actually understood me right, but my answer wasn’t clear enough. Now that the ball is rolling at a constant speed, is there a way to make it accelerate the way it would normally do if there was a big impact ?
I want the player to feel that the ball has been punched or something.