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 dht1kna · May 08, 2012 at 04:10 PM · cameragameobjecttransformtransform.positionfollow

Find transform.position of Another Game Object

I tried to make a Camera Follow script. The first thing i did was to set the position of the camera to the players position.

Here is the code i used in javascript:

  var follow : GameObject;
 
 function Update () {
      var FollowTransform : Transform = (follow.gameObject.GetComponent(Transform));
      transform.position = FollowTransform.position;
 }

But when the game started the camera changed position to where the player was at the beginning of the game but remained there. The FollowTransform.position only returned the initial position of the player. What did I do wrong?

Comment
Add comment · Show 3
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 Jessy · May 08, 2012 at 04:18 PM 0
Share

"GetComponent(Transform)" - no. .transform - yes. gameObject is also useless; it IS a Game Object.

avatar image dht1kna · May 08, 2012 at 04:23 PM 0
Share

I did what you said but it gave the same result

avatar image Drakestar · May 08, 2012 at 05:00 PM 0
Share

you get what you're actually doing here: you're transferring the values of the initial player position into a new variable (copy by value rather than creating a reference. They're not automatically linked - one won't update when the other one does.

Creating a real camera is more involved. Rather than having somebody reexplain it here, you should google a couple of tutorials on the subject first and see if you have questions afterwards.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by centaurianmudpig · May 08, 2012 at 04:58 PM

You can set the camera as a parent to your game object. That way it will "follow" your game object.

i.e. var FollowTransform : Transform = (follow.gameObject.GetComponent(Transform)); transform.parent = FollowTransform;

You can adjust the position and rotation of the camera, in relation to the game object, using localPosition and localRotation.

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

(C#) Follow target (script) transform target PREFAB 0 Answers

Trouble converting transform.position to C# 1 Answer

Confuse about transform.InverseTransformPoint 1 Answer

how to reference GameObjects to GUIButton??? 1 Answer

2D boundaries for player gameobject not moving with scrolling camera 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