Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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
10
Question by gabosuelto · Aug 16, 2011 at 05:58 AM · camerajavascriptgameobjectposition

How get position from a game object?

Im trying to make a cam follow a gameobject, and I don't know how get the position of the object. helpme please

Comment
Add comment · Show 1
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 josemauriciob · Jan 30, 2015 at 08:52 AM 0
Share

can i store the value on a var... something like this ?

myvalue = GameObject.FindGameObjectWithTag("Your_Tag_Here").transform.position;

5 Replies

· Add your reply
  • Sort: 
avatar image
32

Answer by jimmycrazyskills · Jan 06, 2014 at 08:31 PM

You can find the object by the object tag.

 GameObject.FindGameObjectWithTag("Your_Tag_Here").transform.position;

Or you can find the object by the name of the object.

 GameObject.Find("Your_Name_Here").transform.position;

Hope that works ;)

Comment
Add comment · Show 7 · 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 impurekind · Aug 20, 2018 at 06:17 PM 0
Share

But what do I actually need to do to use that line of code?

The script is telling me something is wrong by showing the little red under markings on this code if I simply insert into the Start function of my script as is, so clearly there needs to be other stuff setup around this line of code to get it to work.

Can you tell me what that other stuff is please?

avatar image MT369MT impurekind · Aug 20, 2018 at 06:21 PM 0
Share

If you need help post your current script so someone can help you.

avatar image impurekind MT369MT · Aug 20, 2018 at 08:11 PM 0
Share

$$anonymous$$y script is literally just what is above (it's a new script with that line of code pasted into the start function to find the position of the other object). I haven't added anything else yet. The point is that code doesn't work without something else that has not been mentioned above, something that's obviously been taken for granted and assumed everyone knows to do already by the original poster, and I'm just trying to figure out what "obvious" thing it is that has been omitted so I can add it and get it to work properly.

Show more comments
avatar image
5

Answer by Waz · Aug 16, 2011 at 06:08 AM

https://docs.unity3d.com/Manual/ControllingGameObjectsComponents.html

Read The Fine Manual.

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 impurekind · Aug 20, 2018 at 08:19 PM 7
Share

What's the point in having a help forum to ask questions for issues you can't resolve if people like you just tell the stumped people to go read the manual? Do you seriously think they're so dumb that they didn't try more than one way to fix the issue, of which one of them was to come to the help forum and ask for help from people who have more experience and knowledge than they do and might want to use that to help them? The point is the manual often doesn't explain things clearly enough or use an example that the person asking in here has been able to apply in their specific situation, so they're asking for advice from the community. And then there's this too: https://docs.unity3d.com/410/Documentation/ScriptReference/index.Accessing_Other_Game_Objects.html

avatar image
3

Answer by krewnel · Jan 06, 2014 at 07:05 PM

If the script you are using is atached to the object for which you want the position it is as simple as

Vector3 bar = transform.position;

otherwise you need to get an instance of the object of which you want the position:

foo = Object_In_Scene.GetComponent(); Vector3 bar = foo.position;

It's all a matter of relativity.

"Read The Fine Manual." ~Waz

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
1

Answer by Victor2006 · Mar 11, 2017 at 07:16 PM

Hello @gabosuelto! if you want to make the MainCamera follow a GameObject, you can write a C# Script, but the simplest thing to do is drag your MainCamera onto the GameObject.

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 $$anonymous$$ · Aug 15, 2019 at 12:10 PM 0
Share

Well then try to drag your $$anonymous$$ainCamera onto a GameObject, and if you have a game in which you rotate a ball, make that ball rotate.

avatar image
0

Answer by Supphakon · Apr 14, 2020 at 12:27 AM

You can learn it from : GameObject.Find

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

18 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

Related Questions

How can I get my camera to follow a clone after a certain trigger occurs? 2 Answers

Is it possible to summon specific GameObjects (i.e. from Assets) on a specific position in a jagged array so that I can later Destroy said object? 0 Answers

Change the active value quickly? 1 Answer

Rotation around player. and Camera position, 2 Answers

speed = transform.rotation * speed; explanation please? 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