- Home /
How to account for situation using RotateAround
If you look at the video here: http://screencast.com/t/Y4eYOz3x
You'll see that I'm using the Function Rotate around to rotate the transform around the plane. Going around the Y axis works fine up until I rotate around the X axis 90°. Then it rotates around itself when I actually want it to go upwards (as demonstrated in the video).
 using UnityEngine;
 using System.Collections;
 
 public class PlayerController : MonoBehaviour {
     public float deadZone;
     public float speedMultiplier;
     public float rotationMultiplier;
     public float rotationAngleSpeed;
     public float idleSpeed;
     public Transform moveTowardsPoint;
 
     private Vector3 movement;
     private Vector3 rotation;
 
     private void MoveX(float v, bool b) {
         if (b && Mathf.Abs(v) <= deadZone) return;
         Vector3 movedirect = Vector3.zero;
         movedirect = new Vector3(v * speedMultiplier, 0f, 0f);
         movedirect = this.moveTowardsPoint.TransformDirection(movedirect);
         this.movement += movedirect;
     }
 
     private void MoveY(float v, bool b) {
         if (b && Mathf.Abs(v) <= deadZone) return;
         Vector3 movedirect = Vector3.zero;
         movedirect = new Vector3(0f, v * speedMultiplier, 0f);
         movedirect =  this.moveTowardsPoint.TransformDirection(movedirect);
         this.movement += movedirect;
     }
 
     private void MoveZ(float v, bool b) {
         if (b && Mathf.Abs(v) <= deadZone) return;
         Vector3 movedirect = Vector3.zero;
         movedirect = new Vector3(0f, 0f, v * speedMultiplier);
         movedirect = this.moveTowardsPoint.TransformDirection(movedirect);
         this.movement += movedirect;
     }
 
     private void RotateX(float v, bool b) {
         if (b && Mathf.Abs(v) <= deadZone) return;
         Vector3 movedirect = Vector3.zero;
         movedirect = new Vector3(v * speedMultiplier, 0f, 0f);
         this.rotation += movedirect;
     }
     private void RotateY(float v, bool b) {
         if (b && Mathf.Abs(v) <= deadZone) return;
         Vector3 movedirect = Vector3.zero;
         movedirect = new Vector3(0f,  v * speedMultiplier, 0f);
         this.rotation += movedirect;
     }
 
     // Update is called once per frame
     void Update () {
         if (Input.GetKey ("j")) this.RotateY (-this.rotationMultiplier, false);
         if (Input.GetKey ("l")) this.RotateY (this.rotationMultiplier, false);
         if (Input.GetKey ("i")) this.RotateX (-this.rotationMultiplier, false);
         if (Input.GetKey ("k")) this.RotateX (this.rotationMultiplier, false);
         if (Input.GetKey ("u")) { this.RotateX (this.rotationMultiplier, false); this.RotateY (this.rotationMultiplier, false); }
         if (Input.GetKey ("o")) { this.RotateX (-this.rotationMultiplier, false); this.RotateY (-this.rotationMultiplier, false); }
 
         this.moveTowardsPoint.RotateAround(this.transform.position, this.rotation, rotationAngleSpeed * Time.deltaTime);
         print ("" + rotation);
 //        this.moveTowardsPoint.rotation = this.transform.rotation;
         this.rotation = Vector3.zero;
 
         this.moveTowardsPoint.transform.position += this.movement;
         this.movement = Vector3.zero;
 
 
 //        this.MoveZ (this.idleSpeed, false);
 
         // xbox
         this.MoveX(Input.GetAxis("XBOX360_LEFTSTICK_X_AXIS_ALL"), true);
         this.MoveY(Input.GetAxis("XBOX360_LEFTSTICK_Y_AXIS_ALL"), true);
         this.MoveZ(Input.GetAxis("XBOX360_RIGHT_TRIGGER_X_AXIS_ALL"), true);
 
         // keyboard
 //        this.transform.LookAt (this.moveTowardsPoint.position);
         if (Vector3.Distance (this.transform.position, this.moveTowardsPoint.position) > 20.0f)
             this.transform.position = Vector3.Slerp (this.transform.position, this.moveTowardsPoint.position, 0.01f);
     }
 }
 
Note that moveTowardsPoint is the Transform in front of the plane.
Which you are rotating around the current transform? Just finding it a little hard to work out the effect that you want with these components and trying to relate it to the video of what is happening :)
Perhaps you could describe in words what you want the control system to be? Sorry...
Your answer
 
 
             Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Flip over an object (smooth transition) 3 Answers
Orbit Camera Around Player And Add Force 3 Answers
Shooting problem the bullets fly in diffrent direction then player looks? 2 Answers
transform.Rotate will not work 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                