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
1
Question by cry-gun · May 16, 2015 at 11:22 AM · cameramove an objectcamera followcamera movementrelative position

move a child object to a specific xyz coordinates

hello i have a problem when trying to move my camera to a xyz coordinates relative to the parent object (3rd person controller) im using this class/script attached to the camera, and calling it's methods from another script with the xyz values.

 using UnityEngine;
 using System.Collections;
 
 public class PosCam : MonoBehaviour {
 
     public void chPos(Vector3 val)
     {
         this.transform.position = val;
         //transform.position = val;
         //gameObject.transform.position = val;
     }

     public void chPos(Vector3 val, float x, float y, float z)
     {
         this.transform.position = val;
         //transform.position = val;
         //gameObject.transform.position = val;
        this.transform.Rotate(x, y, z);//no problem in this line for now
     }
 }

the problem is, no matter if i send 0,0,0 as the "val" value, this is sending the position of my camera to a crazy position like 500,-9,80 something like that. image with the hierarchy attached, my player seems like thatalt text

pd: im trying to move my camera for a "first person view" in some places.

any suggestion will be very appreciated. thanks for reading

capture.png (9.2 kB)
Comment
Add comment · Show 2
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 felixpk · May 16, 2015 at 11:38 AM 0
Share

Hey, first of all, don't overload your method, they are simply not doing the same with different parameters, then "transform.Rotate()" will not give you the results you are expecting. Use localEulerAngles ins$$anonymous$$d.

avatar image cry-gun · May 16, 2015 at 02:39 PM 0
Share

Ok, thanks for the help, i will use one method, but, i still have the problem trying to set a position on the camera....it keeps going to another place...so far from it's parent gameObject... :/

2 Replies

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

Answer by FortisVenaliter · May 16, 2015 at 03:08 PM

Try using transform.localPosition instead of transform.position.

Transform.position uses Scene Coordinates. Transform.localPosition uses coordinates local to the parent object.

So, setting Transform.localPosition to (0,0,0) will make it match the location of the parent.

Comment
Add comment · Show 1 · 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
avatar image cry-gun · May 16, 2015 at 03:45 PM 0
Share

problem solved, thank you very much!!

avatar image
1

Answer by TrainWrek · May 16, 2015 at 04:41 PM

Try using transform.localPosition

Comment
Add comment · Show 1 · 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
avatar image Bunny83 · May 16, 2015 at 04:44 PM 0
Share

Too bad, this answer was stuck in the moderation queue for 4 hours ^^. So i gave you also a +1.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Camera Follow a Target, but not Centered on it 1 Answer

Camera follow players z axis 0 Answers

How to get the camera's size in world units 1 Answer

Rotate camera a set amount of degrees around Player 0 Answers

FPS cam for Roll -a-Ball like game 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