Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Darkomen43 · Dec 23, 2017 at 09:15 AM · script.vector3axismethods

Method not able to see Vector3 axis

I am successfully (for the most part) trying to make my camera follow a player. I am using the Z axis like a Y axis. I have set a movement script to check the players position and then follow accordingly.. the script all works fine in the update function but once i put it in its own method the camera gos wonky.

void Update () {

     Vector3 CharPos = GameObject.Find("Character").transform.position;
     Vector3 RelevantPos = new Vector3 (this.transform.position.x, this.transform.position.y, (CharPos.z -8));
     Vector3 RelevantRotation = new Vector3((-CharPos.z + 25f), this.transform.rotation.y, this.transform.rotation.z);
     
     if (CharPos.z >= (-8.5f) && CharPos.z <= (4f)) {        
         FollowPlayer(); 
         
     } 
 }
 
 void FollowPlayer () {
     
     this.transform.position = RelevantPos;
     this.transform.eulerAngles = new Vector3 (RelevantRotation.x, transform.eulerAngles.y, transform.eulerAngles.z); 
     
 }
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

Answer by Darkomen43 · Dec 23, 2017 at 11:18 PM

I have fixed my issue, not sure if I have done so the best way and would still like input on the culprit but here it is working to pitch, pan, and zoom around the character. However this requires Vector3 CharPos = GameObject.Find in each method, Update, FollowingPlayer, and PanPlayer . Why it has to be in each method separately im not quite sure?

 void Update () {
 
     
     Vector3 CharPos = GameObject.Find("Character").transform.position; // Camera World Bounds

     if (CharPos.z >= (-8.5f) && CharPos.z <= (4f)) {     //These are just confining the player to the area    
         FollowPlayer();
     }
         
     if (CharPos.x >= (9.3f) && CharPos.x <= (22.5f)) {     //These are just confining the player to the area
         PanPlayer();
      }
  }    
 
 void FollowPlayer () {
     
     Vector3 CharPos = GameObject.Find("Character").transform.position;
     Vector3 RelevantPos = new Vector3 (this.transform.position.x, this.transform.position.y, (CharPos.z -8));
     Vector3 RelevantRotation = new Vector3((-CharPos.z + 25f), this.transform.rotation.y, this.transform.rotation.z); //Pitch
     this.transform.position = RelevantPos;
     this.transform.eulerAngles = new Vector3 (RelevantRotation.x, transform.eulerAngles.y, transform.eulerAngles.z); 
     
 }
 
 void PanPlayer() {
 
     Vector3 CharPos = GameObject.Find("Character").transform.position;
     Vector3 RelevantPos = new Vector3 (CharPos.x, this.transform.position.y, this.transform.position.z);
     this.transform.position = RelevantPos;
         
 }

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

138 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 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

I cant figure out what is wrong with my code 1 Answer

X-Axis rotation quirk 0 Answers

Problem with aiming Script(Only Some Code Works) 0 Answers

Detecting Rays from controller input and cast from Object 0 Answers

Vector3 is not receiving enough arguments from a another script that gives out transform.position. 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