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 TamboFirstBlood · Jun 23, 2011 at 04:25 PM · positionscalelinkautomatically

How do I link Position and Scale?

Hi everyone,

I am an animator and not a programmer so please bare with me as I do my best to ask a programmy question :)

I created a photoshop scene which has 3 layers: Foreground, Midground and Background.

I imported these layers onto 3 separate planes in Unity as textures and set the planes up in 3D space so I could create a parallax effect between the 3 layers when I move the camera.

When I moved the Midground and Foreground planes closer to the camera I had to scale them down so they maintained the correct size in relation to the Background.

Does anyone know if there a way in Unity to link the position and scale properties of a plane? I have lots of scenes to set up in Unity so it would be awesome if the planes scaled down automatically as I moved them closer to the camera.

Thanks

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
0

Answer by flaviusxvii · Jun 23, 2011 at 04:33 PM

You probably want an Orthographic camera.

http://unity3d.com/support/documentation/Components/class-Camera.html

Comment
Add comment · Show 4 · 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 TamboFirstBlood · Jun 23, 2011 at 04:39 PM 0
Share

Thanks for the speedy response. Unfortunately with an Orthographic camera there won't be any sense of 3D space/Depth to the scene i.e. the Foreground, $$anonymous$$idground and Background planes will all move together at the same speed when I move the camera and there won't be any parallaxing effect.

avatar image flaviusxvii · Jun 23, 2011 at 05:04 PM 0
Share

Ah.. I misunderstood you. In that case I'd use this http://unity3d.com/support/documentation/ScriptReference/GeometryUtility.CalculateFrustumPlanes.html and then interpolate between the height of the close plane and the far plane to get the right height for any give layer at any given distance.

avatar image Graham-Dunnett ♦♦ · Jun 23, 2011 at 05:56 PM 0
Share

but you could move the foreground, middle and background planes at different speeds to recreate the parallex effect.

avatar image flaviusxvii · Jun 23, 2011 at 06:38 PM 0
Share

I was right all along! Brava to me!

avatar image
0

Answer by sneftel · Jun 23, 2011 at 05:05 PM

Here, try this script. The "scale" parameter is the global scale factor, which should be set the same for all layers. Change "targetCamera" if you want a camera other than the main camera controlling the scale.

 using UnityEngine;
 
 [ExecuteInEditMode]
 class ScaleFromDistance : MonoBehaviour
 {
     public Camera targetCamera = null;
     public float scale = 1;
     void Update()
     {
         Camera usedTargetCamera = (targetCamera == null) ? Camera.main : targetCamera;
         float overallScale = scale * usedTargetCamera.transform.InverseTransformPoint(transform.position).z;
         transform.localScale = Vector3.one * overallScale;
         if (Application.isPlaying)
         {
             Destroy(this);
         }
     }
 }
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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Why does my object disappear? 1 Answer

Auto-rounding positions of game objects dragged into scene 1 Answer

How to visualize Object with precise Size and Position 0 Answers

Position and scale GameObject according to screen size 2 Answers

Wheelcolliders bug ? 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