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 DevMerlin · Jan 11, 2015 at 02:18 AM · cameraresolutionoffset

Can I keep a player on the left side of the screen in relation to view resolution?

I'm working on my latest project, which is a action sidescroller, primarily 2D but using a perspective camera for 3D effect. I've gotten the basics working - design, etc, and now fixing the camera so that it follows correctly. However, I'd like to keep the player on the left side of the viewport - not actually modifying the player's position, but the camera following an offset. I have it partially worked out, but it broke the moment I started playing around with other alternative resolutions - say, from web standard, standalone, to mobile devices. This is what I want to do:

Resolution Display

Here is the code I have so far, the offset is already in place and does work, but it's not set for multiple resolutions - that is what I am trying to figure out:

     public static GameCamera Instance;
 
     public Vector3 TargetOffset = Vector3.zero;
     
     public Transform TrackTarget;
     
     public float dampTime = 0.15f;
     
     public bool Ready = false;
     
     private Vector3 velocity = Vector3.zero;
     
     void Awake()
     {
         Instance = this;
     }
 
     void Start()
     {
         Vector3 point = TrackTarget.position + TargetOffset;
         Vector3 Destination = new Vector3(point.x, transform.position.y, transform.position.x);                
         transform.position = Destination; 
     }
     
     void FixedUpdate () {
         if (Ready) {
             if (TrackTarget)
             {
                 Vector3 point = TrackTarget.position + TargetOffset;
                 Vector3 Destination = new Vector3(point.x, transform.position.y, transform.position.x);                
                 transform.position = Vector3.SmoothDamp(transform.position, Destination, ref velocity, dampTime);
             }
         }
     }
     
     void LateUpdate()
     {
         if (Ready) {
             Vector3 CameraPosition = transform.position;
             CameraPosition.z = -30.00f;
             transform.position = CameraPosition;
         }
     }

cameraoffsetdemo.png (22.8 kB)
Comment
Add comment · Show 3
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 SnStarr · Jan 11, 2015 at 05:53 AM 0
Share

Can you just make the camera a child of the player and move the camera so it "looks" offset. Then the camera will follow the player whenever it moves and will remained offset?

avatar image DevMerlin · Jan 11, 2015 at 06:13 AM 0
Share

No. The camera needs to remain independent in order to be unaffected by the player's rotation.

avatar image DevMerlin · Jan 11, 2015 at 07:42 AM 0
Share

And as an additional comment, the issue still stands even when the camera is a child of the player. It does not keep the player in focus automatically. If the resolution is adjusted, or changed to a different device, the player may not even be on screen without some moderately heavy code.

0 Replies

· Add your reply
  • Sort: 

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

26 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

Related Questions

Is it possible to keep the player offset in place on the screen independent of resolution? 1 Answer

resolution is squished horizontal on android 0 Answers

How to set constant orthographic viewport? 1 Answer

how to shrink the cameras resolution in unity 3d 1 Answer

Pixel Perfect Camera Consistent World Size 0 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