Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Rotating a rolling ball

Discussion in 'Editor & General Support' started by Croatoan, Apr 9, 2014.

  1. Croatoan

    Croatoan

    Joined:
    Mar 27, 2013
    Posts:
    3
    Hi , i am making a game of a rolling ball , but i am having a trouble with the ball rotation , i can move it using input.getaxis Horizontal/Vertical and adding force to move the ball , the problem is after rotating the camera , cause if i rotate it for example for 90° , if i pressed the "W" key the ball will start moving the left instead of forward , that's cause i rotate only the camera but not the ball , i found a solution for this problem by inverting Horizontal and Vertical input axis when i rotate the camera , but it still not a good solution for my problem , i tried Add.torque , it rotates the ball around the Y global axis , if i rotate it the camera should rotate with the ball left or right , but this did't work :(
     
  2. iMob

    iMob

    Joined:
    Apr 9, 2014
    Posts:
    55
    I think you mean, you want that the forward direction of the ball (W key) can be different directions, based on the actually camera direction. Right?
    Your camera should always stay behind the ball, i think. So you can make the camera a child object of the ball by drag&drop the camera in the hierachy-view onto the ball. If you then rotate the ball, the camera will rotate with the ball.

    also take a look at:
    http://unity3d.com/learn/tutorials/projects/roll-a-ball
     
    Last edited: Apr 9, 2014
  3. Croatoan

    Croatoan

    Joined:
    Mar 27, 2013
    Posts:
    3
    Hi iMob , i used that tutorial that you linked to make the movement of the ball , my MainCamera is a child of the ball object , at the begining , when i added the camera to the ball object , the camera was rotating everywhere with the ball , i fixed that by making a script that make the cam stay behind the ball , i can move the ball forward , back , right and left , but i still got the problem of the rotation , even if i rotate the camera , my W direction isn't the same after rotation cause if i pressed W after rotating the camere the ball will move to the left and not forward
     
    Last edited: Apr 9, 2014
  4. Croatoan

    Croatoan

    Joined:
    Mar 27, 2013
    Posts:
    3
    Just to clarify what is happening and what I am trying to do , in the first image the camera rotate but the ball not
    $what happens.jpg
    What I am trying to do is in this image
    $what I want.jpg
    i want to rotate the ball with the cam
     
  5. iMob

    iMob

    Joined:
    Apr 9, 2014
    Posts:
    55
    and you want to rotate the input directions with the ball/cam.

    if you use the script from tutorial, you add force with a vector3, set by the input.GetAxis. Key W is always the same direction in world space.
     
    Last edited: Apr 12, 2014