Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by theMonster · Feb 19, 2014 at 01:47 AM · c#rotationcamera rotaterotate object

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);
     }
 }
 
Comment
Add comment · Show 6
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image whydoidoit · Feb 19, 2014 at 07:12 AM 0
Share

Can you post your code?

avatar image theMonster · Feb 19, 2014 at 08:26 AM 0
Share

Just did..

avatar image theMonster · Feb 19, 2014 at 08:27 AM 0
Share

Note that moveTowardsPoint is the Transform in front of the plane.

avatar image whydoidoit · Feb 19, 2014 at 10:13 AM 0
Share

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 :)

avatar image whydoidoit · Feb 19, 2014 at 10:13 AM 0
Share

Perhaps you could describe in words what you want the control system to be? Sorry...

Show more comments

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

19 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges