Search Unity

Question about the ball physics

Discussion in 'Scripting' started by DarkSoul, Apr 21, 2010.

  1. DarkSoul

    DarkSoul

    Joined:
    Dec 24, 2009
    Posts:
    37
    Hello.
    I'm created a game similar to Marble Blast, but I do not know how to move the ball into the direction that looks at the camera, any idea? (I move the ball with physics)
     
  2. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    If you want to use torque to roll the ball, apply it around the camera's rightward direction:-
    Code (csharp):
    1. rigidbody.AddTorque(camera.transform.right * torqueStrength);
    If you want to push the ball, add the force in the camera's forward direction:-
    Code (csharp):
    1. rigidbody.AddForce(camera.transform.forward * pushStrength);
     
  3. DarkSoul

    DarkSoul

    Joined:
    Dec 24, 2009
    Posts:
    37
    Ah, ok!, thanks! but now I have other problem. The addTorque is not working well. The velocity is very slow, although increase, for example, if the velocity is: 100 and later I change the velocity to 200, the ball rotate to the same speed that 100. Why?
     
  4. pavees

    pavees

    Joined:
    Jan 1, 2009
    Posts:
    116
    hi, i hav created a slope plane and over which i have ball located to the bottom and on the swipe of the finger i need to move the ball in the direction i have swiped, and then apply a force so that it can be rolled over the plane to go forward. And the force applied over the ball can be determined by the length of the swipe in the vertical(Y) axis. Pls if some one have a demo or sample script that one could share to me.
    Thanks in advance