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 amazingdude123 · Oct 31, 2014 at 06:44 PM · rotationmovementcamera-movementparent and child

Stop camera from moving when parent rotates forward

All code in C#. I am making a 3rd person camera system. I have added rotation to a cube and this all works fine as I want it this is only for reference purposes so you can see what the box is doing, see code below:

 public float speed = 6.5f;
 // Update is called once per frame
 void FixedUpdate()
 {
     if (Input.GetAxis("RightStickVertical") < 0f)
     {
         rigidbody.AddTorque(transform.right * speed);
     }

     else if (Input.GetAxis("RightStickVertical") > 0f)
     {
         rigidbody.AddTorque(transform.right * -speed);
     }
 }

}

I have added a camera to the cube i.e. made it the child of the cube so the camera will follow the cube. To keep the camera facing the same direction (forward) I have used Quaternion.

The problem comes when the box rotates forward to move forward the camera also rotates with it i.e. the cube rotates 90 degrees forward the camera is now positioned over head. I want the camera to remain behind the cube at all times and only move forward with the cube and not up and over when the cube moves.

I am aware that a way of doing this is to make it so if the cube moves 90 degrees forward for example the camera moves 90 degrees backward so it remains in the same position, however I don't know how to do this.

Any help for any type of solution would be appreciated thanks.

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by amazingdude123 · Nov 02, 2014 at 06:30 PM

I have fixed this problem. I created an empty game object and in the update method I transformed it's position to that of the cube. I then made the camera a child of the empty game object and this works perfectly. Here is the code for instantly moving the empty game object to the cube in case anybody needs it:

public GameObject box;

 void Update () 
 {
     transform.position = box.transform.position;
 } 

Place the object you want the empty game object to transform to in the inspector in unity.

Comment
Add comment · Share
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

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

2 People are following this question.

avatar image avatar image

Related Questions

Panning and Rotating a Camera 0 Answers

click to move workig script!! but pls help with rotation!! :( 1 Answer

How to make a RigidBody not go into ground when tilted foward? 2 Answers

Undesirable character flipping 0 Answers

How can I keep my z-axis perpendicular to a target location while simultaneously rotating around the x-axis 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