special ball physics

Hi,

I will start my question with this online démo

The ball can jump with SPACE, and rotate with WASD. The camera orbit with MOUSE X, and the ball rotate around Y with MOUSE X also.

The ball is a game object with physics components :

  • rigidbody with locked rotations
  • a sphere collider

it as 2 children :

  • the camera
  • a mesh for rendering

you can read the script by right clicking on the web page and view the source code. It’s in Javascript.

My problems :

  • when the ball (the rendering one, not the physic one) is rotating on the ground it don’t rotate at the right speed. The physic ball move faster and faster but I don’t know how to rotate the render ball at the right speed.

  • when jumping the jumpforce is added to the bounce, so it jump to much. I would like to set a maximum height for jump and bounce.

  • the force added to the physics ball is not strong enought and don’t depend on the render ball rotation.

thanks

Hi

First question:
Make a sphere, attach a rigidbody and your script. Don’t set lock rotation to true.
In the script use rigidbody.AddTorque (camerasRightDirection*speed*Time.deltaTime); When you want to go forward.

Calculate camerasRightDirection by using Transform.TransformDirection (Vector3.right) on the camera
That would make the ball roll forward with good looking physics.
The camera should not be a child of the ball