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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Using RotateAround with a controllers input (using InControl)

Discussion in 'Scripting' started by astralmedia, May 26, 2016.

  1. astralmedia

    astralmedia

    Joined:
    May 18, 2016
    Posts:
    2
    Hey! I am trying to have an object move around a point, with the same distance from the point always. I want to allow the user to control the point, but my code doesn't seem to do the job.

    I am using InControl ( http://www.gallantgames.com/pages/incontrol-introduction )

    Code (CSharp):
    1.  
    2.         var CAMERA_POSITION = Camera.main.gameObject.transform.position;
    3.         var SPEED_RATIO = 400;
    4.  
    5.         float rightRotation = inputDevice.RightStickY * SPEED_RATIO;
    6.         float leftRotation = inputDevice.LeftStickY * SPEED_RATIO;
    7.  
    8.         rightEmitter.transform.RotateAround (CAMERA_POSITION, Vector3.forward, rightRotation * Time.deltaTime);
    9.  
    It does move the object, but it isn't moving in the obvious way you would expect a controller to move it.

    Thanks a bundle! :)
     
  2. traderain

    traderain

    Joined:
    Jul 7, 2014
    Posts:
    108
    I would suggest calculating the point with something like this and the using Math.Lerp() to make it smoother:
    Code (CSharp):
    1. static Point RotatePoint(Point pointToRotate, Point centerPoint, double angleInDegrees)
    2. {
    3.     double angleInRadians = angleInDegrees * (Math.PI / 180);
    4.     double cosTheta = Math.Cos(angleInRadians);
    5.     double sinTheta = Math.Sin(angleInRadians);
    6.     return new Point
    7.     {
    8.         X =
    9.             (int)
    10.             (cosTheta * (pointToRotate.X - centerPoint.X) -
    11.             sinTheta * (pointToRotate.Y - centerPoint.Y) + centerPoint.X),
    12.         Y =
    13.             (int)
    14.             (sinTheta * (pointToRotate.X - centerPoint.X) +
    15.             cosTheta * (pointToRotate.Y - centerPoint.Y) + centerPoint.Y)
    16.     };
    17. }
    18. static Point RotatePoint(Point pointToRotate, double angleInDegrees)
    19. {
    20.    return RotatePoint(pointToRotate, new Point(0, 0), angleInDegrees);
    21. }
    22. static double DegreesToRadians(double angleInDegrees)
    23. {
    24.    return angleInDegrees * (Math.PI / 180);
    25. }
    26.  
    http://stackoverflow.com/questions/13695317/rotate-a-point-around-another-point
     
  3. astralmedia

    astralmedia

    Joined:
    May 18, 2016
    Posts:
    2
    Can you explain a lil more how to go about integrating that?

    How would I connect that to the controller input?