• 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 Kalbytron · Nov 18, 2013 at 08:09 AM · cameratransformoffset

Offsetting local positions

I have been trying to figure out how to use a vector3 as a offset for local transforms in scripting.

Ex: An orbit camera looking at a the player. I want to use a vector3 to position the lookat point slightly to the right of character. Also, when I rotate the camera, the offset should rotate with the camera so the offset stays on the right. Instead of that happening, the offset moves the lookat point on the world x-axis instead of the local axis.

How do I get it to offset on the local axis?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by GameVortex · Nov 18, 2013 at 11:22 AM

So you want the position to be on the right of the player relative to the camera?

You are close, you just have to move it with the cameras axis instead of world as you said.

It can be done like this:

 Vector3 playerPosition;
 float xOffset;
 Camera camera;
 
 Vector3 lookAtPoint = playerPosition + (camera.transform.right * xOffset);
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 Kalbytron · Nov 18, 2013 at 04:49 PM 0
Share

Hey thanks for the help. This is what I have been looking for. :)

avatar image
1

Answer by Shudrum · Nov 18, 2013 at 11:19 AM

Why not use a empty gameobject ?

You create a gameobject "target" set the character as parent of this target (on the editor), your camera look at this target, so when you move / rotate your character, the target follow the movement and your camera still look at the right point.

(And maybe set the camera the children of this target).

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 ZenMicro · Sep 26, 2015 at 01:21 PM 0
Share

As much as i have tried to use what I thought would be simpler by having a Vector3 offset for my camera that the Player script owns I've had little joy with that approach... with an empty game object CamTarget you position it, and reference it and all the hard work is done.

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

20 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

Related Questions

Help! I want to make a following camera but in with Y position is constant ? 2 Answers

getting the position of player for the minimap to follow 1 Answer

Setting a cube to be exactly size of intersecting camera view plane 1 Answer

How do I set a child object to not rotate if the parent WILL be rotating? 1 Answer

Transform.LookAt - wrong vector 4 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