Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Rotate Around

Discussion in 'Scripting' started by caseyboundless, Apr 20, 2016.

  1. caseyboundless

    caseyboundless

    Joined:
    Oct 17, 2011
    Posts:
    590
    I'm trying to rotate my player object around the golf ball's position. I keep getting errors about points.
    How do I fix this?
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class RotateAroundBall : MonoBehaviour {
    5.  
    6.  
    7.     public Transform ballTrans; // the position of the ball
    8.     public GameObject myBall;   // the ball
    9.  
    10.  
    11.  
    12.  
    13.     // Use this for initialization
    14.     void Start ()
    15.     {
    16.      
    17.         //ballTrans.position  = new Vector3(myBall.transform.position.x, myBall.transform.position.y, myBall.transform.position.z);
    18.     }
    19.  
    20.     // Update is called once per frame
    21.     void Update () {
    22.         RotateGolfer();
    23.     }
    24.  
    25.  
    26.  
    27.     void RotateGolfer()
    28.     {
    29.         if(myBall)
    30.         {
    31.             if(Input.GetKey(KeyCode.RightArrow))
    32.             {
    33.                 transform.RotateAround(myBall.transform.position, Vector3.up * 10 * Time.deltaTime);
    34.  
    35.             }
    36.  
    37.  
    38.  
    39.  
    40.  
    41.         }
    42.  
    43.  
    44.  
    45.     }
    46.  
    47.  
    48.  
    49.  
    50. }
    51.  
     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    You need to have another look at the scripting reference for the function. It takes three parameters, not two.

    http://docs.unity3d.com/ScriptReference/Transform.RotateAround.html

    generally it's best to paste the error into the forum along with the code, at least then we get all the information...