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 989Nintendo898 · Mar 09, 2015 at 11:54 AM · cameraoffsetbehaviour

Smooth offset on a third person camera

I'm a beginner in Unity, but I'm trying to create a third person shooter with the emphasis being more on the point where the player is looking rather than the player itself.

So what I want to do is: the camera orbits the player, but is always offset over either side so the player is never in the middle. The offset should change depending on what direction the player is turning towards: if the player turns left, the camera offset should be on the left side of the player and if turning right, the offset would be on the right side.

Hopefully you get what I mean.I could've sworn I saw an example of this somewhere, executed on Unity but I can't find it anywhere anymore. I'm currently using unmodified SmoothFollowCamera.js script for the camera.

EDIT: I forgot to mention that the camer should be looking at a gameobject called AimTarget. I have this piece already, the question is merely about the position of the camera, in relation to the player.

Thanks in advance.

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
0

Answer by Cherno · Mar 09, 2015 at 12:24 PM

In this part of the SmoothFollow script:

 transform.position -= currentRotation * Vector3.forward * distance;

You see that the camera's position is updated. That means that it's here where you can add another line of code to make it not only be somewhere on the z axis, but also on the x axis:

 transform.position -= currentRotation * Vector3.forward * distance + target.right * offset_x;

offset_x is a variable we have to declare in the main body; Set it to 2f for now:

 public float offset_x = -2f;


Now you just have to check if the player is turning left or right (turnvector, mouse axis movement or whatever, depending on how you control your character). If hhe turns left, you just set the offset_x value to 2:

 if(playerturnsLeft) {
      offset_x = 2;
 }
 else {
      offset_x = -2;
 }

If you don't use a gameObject target variable but rather just a Vector3 directly as the camera_s position to look at, you would use the camera's transform.right Vector3 instead.

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.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Unity 2D Position Issues 0 Answers

Cinemachine Virtual Camera offset not normalized 0 Answers

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

How to position the main camera in its script? 1 Answer

Position camera between two players 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