Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 unity_Z70jaPTIIp7DuQ · Jan 19, 2018 at 05:02 PM · camera-movementtransform.positionfollow player

Strange thing happening

Hello. I am trying to make the main camera to follow the player. Offset is currently set to 0, 0, 0. So it should place camera right into the centre of my player (cube). But instead, this happens: player position is 0, 1, 0. Camera position sets to 0, 1.48, -6.

I tried

 public Transform player;
 public Transform Camera;
 public Vector3 offset;

 void Update()
 {
  Camera.position = player.position + offset;
 }

and

 public Transform player;
 public Vector3 offset;

 void Update()
 {
     transform.position = player.position + offset;
 }

both have the same result

Well, if someone of you could help me out, I would be happy. But could someone try to teach me a bit? Maybe teaching is not the right word. Just a help here and there (maybe more in the beginning). I watched and followed some YT videos but I just feel like I did not learn anything and I am just copying... but when I try to create something on my own it never works. I would be happy if someone helped me out.

Thank you for your time.

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
1

Answer by spidermancy612 · Jan 19, 2018 at 05:18 PM

I jumped into Unity and tried out your code, and it worked for me. So we know your code works, which means it something else.

~

The first thing I would say is that in the first chunk of code you have, the word "Camera" is a reserved word in the Unity libraries, which means you can't use it for variable names. Instead try something like "theCamera" or "playerCamera".

~

Secondly my guess at what's not working would be a child transform issue. When you have an object nested under another object it gets it own coordinate system separate from the world coordinates. What this means is that 0,0,0 in world space, and 0,0,0 in a nested objects space might not be the same position. To fix this just make sure both the player and the camera are not children of any other object.

~

Failing that fix, let me know and I'll see if I can brainstorm some more. Overall your code should work.

Comment
Add comment · Show 2 · 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 unity_Z70jaPTIIp7DuQ · Jan 19, 2018 at 05:35 PM 0
Share

Camera or player are not a child of anything. Just separate game objects.

And I just deleted the camera and placed another in its place and it is working normally. Strange.

avatar image spidermancy612 unity_Z70jaPTIIp7DuQ · Jan 19, 2018 at 06:35 PM 0
Share

Unity can be weird like that sometimes. Good luck with your game!

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

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

Related Questions

Follow Player in 2D Game 2 Answers

How can you move a camera a set amount of units based on the player's x position in a 2d game? 1 Answer

Multiple Targets Camera 1 Answer

camera problem 0 Answers

Need help updating camera position to go above the player 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