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
0
Question by leafypixiestix · Nov 09, 2014 at 04:54 PM · c#camera2d

Simple script to follow player only shows the camera background

I am making a simple script to follow a character and and for some reason, when I enable the script, it only shows the background of the camera once active and nothing else. Everything renders fine without the script attached. Here's my the important parts of my implementation.

 public Transform target;

 void FixedUpdate () {
     transform.position = new Vector3(target.position.x, target.position.y);
 }

target is set in the inspector to my player game object. Some other information to know is that I can still move my character and when I view the scene, the character is on the camera.

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
2
Best Answer

Answer by robertbu · Nov 09, 2014 at 04:55 PM

Change line 4 to:

  transform.position = new Vector3(target.position.x, target.position.y, transform.position.z);

And this likely should be run in LateUpdate(), not FixedUpdate().

Comment
Add comment · Show 5 · 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 leafypixiestix · Nov 09, 2014 at 06:25 PM 0
Share

I changed my code to what you said and it still doesn't work . . . http://gfycat.com/ConsciousUntidyDinosaur

avatar image robertbu · Nov 09, 2014 at 06:53 PM 1
Share

It is hard to see where the problem is without seeing the transform values of the camera both with and without the the script enabled. So either 1) edit your video, 2) provide the position and rotation values before and after enabling, or 3) put a package of your project on the net. I'll be able to quickly spot the problem if you provide #3.

avatar image leafypixiestix · Nov 09, 2014 at 07:09 PM 0
Share

Here you go: http://www.mediafire.com/download/niru33qq8d0dwyn/TestProject.zip

avatar image robertbu · Nov 09, 2014 at 07:33 PM 1
Share

Your line of code in your BasicCamera script does not match the line I gave you. Look carefully at the added third parameter. It is 'transform.position.z', not 'target.position.z'.

avatar image leafypixiestix · Nov 09, 2014 at 07:39 PM 0
Share

Overlooked that, thanks!

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

2 People are following this question.

avatar image avatar image

Related Questions

how to controll second camera (MiniMap)? 1 Answer

Problem with playmaker gui and "Get mouse button down" action. 1 Answer

Why is Input.mousePosition returning wired values using Cinemachine 2D with dynamic following? 0 Answers

Unassigned Reference Exception 4 Answers

Particle System On Key Press 2 Answers


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