Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 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 /
avatar image
1
Question by CrowdedWorlds · Dec 17, 2011 at 12:02 PM · c#cameraplayervector3offset

C# - Offset In-Air Camera from Current Object Position

Hey folks, pretty straight forward one here. I have a player character object on the ground, and an angled camera in the air. The camera doesn't need to rotate around or anything like that, all I'm wanting to do is have the camera offset from the player character position by a few units. I can't for the life of me remember how to actually reference the player object position inside the cameras transform.Translate vector3.

Can anyone help me out with this derpy one :P

Cheers! Matt

Edit:Basically on the camera, all I wanna do is Transform.position = new Vector3(0,0,PlayerPosition-10)

But I can't dig up the right syntax lol

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

Answer by aldonaletto · Dec 17, 2011 at 12:25 PM

You usually must have a target variable that references the target, and keep some predefined offset from it (camera script):

Transform target; // drag the target here (or find it at Start) Vector3 offset = new Vector3(0, 2, -3); // define the offset

void LateUpdate(){ transform.position = target.position + offset; // you can also force the camera to look at the target: transform.LookAt(target); } This is a very simple following camera script - a more elaborated one could follow the target with Vector3.Lerp in order to have a smoother movement, and possibly keep a constant angle from the target.
NOTE: You can find the target at Start with something like this:

void Start(){
  target = GameObject.FindWithTag("Player").transform;
}
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 CrowdedWorlds · Dec 17, 2011 at 12:47 PM 0
Share

Thanks Aldonaletto, champion :D

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

vector3.forward doesn't work when used in Rigidbody? 2 Answers

Input Controls Camera on a Predetermined Path. 1 Answer

Lock on opponent in UNET (C#) 1 Answer

Release camera 1 Answer

[2D] Looking at mouse is rotated about 90 degrees. 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