• 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 Khaled_A_Younes · Aug 07, 2012 at 05:15 PM · cameraprefabs

make camera follow prefab

I'm trying to get the main camera to follow a sphere. At first I managed to have the camera follow the ball with no problem. But since I'm gonna have the ball instantiated several times I turned the sphere into a prefab. But ever since I did that the camera won't follow the ball anymore.

Here's the code for the camera:

 public var Ball : Transform;

public var cam : Vector3;

function Update () { transform.position = Ball.position + cam; }

I already assigned the prefab so the camera knows what it follows, but the camera doesn't follow the ball. Why isn't the camera following the ball like it should?

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

5 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by adam_melhem · Nov 01, 2012 at 12:47 PM

my friend if you create a new ball in the sense the smooth follow should not follow the original prefab it should follow the new clone , so it should be like this:

i figure out this solution to my self also just 1 min ago .

var new_player_prefab : Transform ; var new_player : Transform ;

function Update ()

{

new_player = Instantiate(new_player_prefab,transform.position,transform.rotation,0); Camera.mainCamera.GetComponent(SmoothFollow).target = new_player ;

}

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 Khaled_A_Younes · Nov 01, 2012 at 01:53 PM 0
Share

thank you :D I'll try it when I get the chance

avatar image
0

Answer by adam_melhem · Oct 30, 2012 at 11:56 AM

add cam "smooth follow"(it in the assets script) and delete the rotation var (at all) from the scripts , i am sure this will work .

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

Answer by agentperrys · Aug 07, 2012 at 07:49 PM

try dragging the camera on the ball from your hierarchy

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 Khaled_A_Younes · Aug 07, 2012 at 10:44 PM 0
Share

But that would make the main camera a child object and the camera will rotate when the ball rotates. I need the camera to follow the ball as it rolls. The ball is the prefab

avatar image
0

Answer by Khaled_A_Younes · Aug 07, 2012 at 07:31 PM

I already told the camera which ball to follow. I assigned the prefab to the camera to have it follow the prefab around, but the camera won't follow the ball :(

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

Answer by Sundar · Aug 07, 2012 at 05:34 PM

You have to tell the camera which ball to follow, when you instantiate a ball, you have created a new gameobject than the one you assigned to the camera before creating the prefab.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

10 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

Related Questions

pressablebutton prefab not showing in camera,i am not able to see my prefab button in camera ? please any one help me 0 Answers

How to update the changes of a camera in runtime while the changes are actually made in the prefab? 0 Answers

Prevent switching to instantiated camera 2 Answers

How to make camera position relative to a specific target. 1 Answer

How can I snap a GameObject to the top-left corner of the Camera in the editor (2D)? 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