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 trevor_kuskibob · Jun 10, 2015 at 07:30 PM · cameraplayerlocationorbit

Where to put camera orbit around player script?

I have been searching around the forums and found a few codes to do what I'm asking for, but I don't have any idea on where to put the code. I've tried making a new script file and copying and pasting the code in there. But that doesn't work. Also I have tried going into the camera move scripts and using those but they don't orbit around the player. So I tried deleting everything in that script and pasting that script into there. That didn't work ether. And after all of this I checked to make sure the programming language was all the same of what type of script document I made. If anyone knows why this is could you tell me what I'm doing wrong?

Comment
Add comment · Show 5
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 trevor_kuskibob · Jun 10, 2015 at 07:53 PM 0
Share

I am trying to use this code:

  using UnityEngine;
  using System.Collections;
  
  public class Orbit : $$anonymous$$onoBehaviour {
  
      public float turnSpeed = 4.0f;
      public Transform player;
  
      public float height = 1f;
      public float distance = 2f;
      
      private Vector3 offsetX;
      private Vector3 offsetY;
      
      void Start () {
  
          offsetX = new Vector3 (0, height, distance);
          offsetY = new Vector3 (0, 0, distance);
      }
      
      void LateUpdate()
      {
          offsetX = Quaternion.AngleAxis (Input.GetAxis("$$anonymous$$ouse Y") * turnSpeed, Vector3.up) * offsetX;
          offsetY = Quaternion.AngleAxis (Input.GetAxis("$$anonymous$$ouse Y") * turnSpeed, Vector3.right) * offsetY;
          transform.position = player.position + offsetX; 
          transform.LookAt(player.position);
      }
  }
avatar image Cherno · Jun 10, 2015 at 08:05 PM 0
Share

So, is this script attached to your camera object? Is the player Transform variable assigned correctly? Does it throw any errors during runtime? What happens when you run the game and move the mouse? Pleaase provide more info.

avatar image trevor_kuskibob · Jun 10, 2015 at 08:28 PM 0
Share

The error it gives me is this:

UnassignedReferenceException: The variable player of Camera_Orbit has not been assigned. You probably need to assign the player variable of the Camera_Orbit script in the inspector.

The script is attached to the camera, I don't know what the player transform variable is and nothing happens when I move the mouse.

Thank you for your help so far :)

avatar image maccabbe · Jun 10, 2015 at 08:34 PM 0
Share

You should have 2 objects the camera and player objects. The script is attached to the camera object. The script has a player variable that you have to set to the player object. Select the camera object so you can see where you have to drag the player object in the inspector. Then drag the player object from the hierarchy to the player variable (in the inspector).

avatar image trevor_kuskibob · Jun 10, 2015 at 08:41 PM 0
Share

THAN$$anonymous$$ YOU SO $$anonymous$$UCH! :D IT WOR$$anonymous$$ED!

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Cherno · Jun 10, 2015 at 08:39 PM

Ok.

This line:

 public Transform player;

means that a variable of Type "Transform" with the name "player" is declared. This variable is meant to reference the Transform component of your player object. The variable will be used by the line

 transform.LookAt(player.position);

. However, you never assigned the Transform component of the player object to the variable, so you get the error when the sxcript tries to access it. What you need to do is drag and drop the player object in your hierarchy over to the inspector window when you have the camera object selected. You will see a small field "player" where the orbiting script is. This will automatically assign the Transform component of the player object to the player variable.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Rotating camera around object up/down problem 0 Answers

3rd person player 0 Answers

Orbit Camera Zoom limit 1 Answer

Animation automatique personnage 0 Answers

Locking world rotation of child 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