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 /
This question was closed Feb 26, 2018 at 03:05 AM by BluetheFox for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by BluetheFox · Feb 26, 2018 at 01:43 AM · movement3dlayersskyboxtransforms

geometric skybox camera?

This problem needs some explaining- what i mean by "geometric skybox", is that i have a sortof miniature version of scenery that i want to render around my level as if i built it full scale. i have 2 cameras, one to follow the player, and one to render the skybox layer geometry's "mini diorama". this works, it renders the diorama at the bigger scale. however, i want the skybox camera to move the way the player moves, but at the smaller scale, so that while the player is moving through the level, the skybox geometry appears to move correctly too.

to heavily simplify this complex issue:

i want object "B" to move when object "A" moves, and move with it, but at a smaller scale (aka, a smaller distance). how do i do this?

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

  • Sort: 
avatar image
1
Best Answer

Answer by Bunny83 · Feb 26, 2018 at 02:34 AM

Well, the easiest, straight forward approach would be to:

  • create your 3d skybox geometry on a dedicated skybox layer.

  • Let the skybox camera only render that dedicated layer and exclude that layer from the main camera.

  • make sure your skybox camera is rendered before the main camera.

  • The main camera's clear flags should be set to "depth only".

  • Add a script to the skybox camera that syncs the movement with the main camera. Here you might specify the scaling factor that should be used for the camera syncing.


Note that it would be a good idea to create an empty gameobject where you add everything related to the skybox (the skybox geometry and the camera). So the empty gameobject would be the "world origin" for the skybox geometry. All your script has to do is this:

 public Transform skyboxCam;
 public Transform mainCam;
 public float scale = 0.1f;
 
 void Start()
 {
     if (mainCam == null)
         mainCam = Camera.main.transform;
     if (skyboxCam == null)
         skyboxCam = GetComponent<Camera>();
 }
 
 void LateUpdate()
 {
     skyboxCam.localRotation = mainCam.rotation;
     skyboxCam.localPosition = mainCam.position * scale;
 }


Note that it's on purpose that we read the worldspace position and rotation from the main cam but setting the local space position and rotation of the skybox camera. This allows us to move / rotate our empty skybox root object whereever we want without changing anything.

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 Bunny83 · Feb 26, 2018 at 02:50 AM 0
Share

$$anonymous$$eep in $$anonymous$$d that such a 3d skybox only makes sense on a restricted world. The "skybox geometry map" should have an empty area in the center (the actual area where the player will move). So make sure when the player reaches the border of your actual map he doesn't intersect with any skybox geometry.


Of course you can calculate the scaling factor based on the inverse which might be more convenient. Also since floating point numbers essentially work in base 2 using a power of two scaling factor would be a good idea ^^. The default scaling factor of the source engine is usually "16" (or "1/16" --> 0.0625)

avatar image BluetheFox Bunny83 · Feb 26, 2018 at 06:09 PM 0
Share

i definetely know about source- i used to use source as my primary dev engine before realizing how antiquated it was and moving to unity after a few years. thats where i got the idea to use a 3d skybox; i have a level where I want it to be in a big city but the player can only go one linear path through it, and building tons of actual-sized buildings is too time consu$$anonymous$$g, so $$anonymous$$atures works better. :)

avatar image Bunny83 · Feb 26, 2018 at 03:02 AM 0
Share

ps: Ins$$anonymous$$d of manually scaling the position you could simply scale the empty root gameobject for the skybox. This will have two effects in one: First everything inside the root will be scaled down. Also you can use the exact same coordinates as in the main world. So when assigning the position to the localPosition the skybox camera will automatically move 10 times slower when the scale is "0.1"

avatar image BluetheFox Bunny83 · Feb 26, 2018 at 04:01 AM 0
Share

thank you! this worked very well; and i was even able to modify the script after i got it working, so that i can toggle a "debug mode" that traces the player's path through the level onto the scaled diorama, allowing me to see how i can structure it without getting weird issues with collision and stuff. :D

Follow this Question

Answers Answers and Comments

123 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 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 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 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 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

raycast in direction of movement key down 2 Answers

Infinite random movement 0 Answers

How do I stop my character from sliding after adding force? 0 Answers

Player Control Script Makes Movement Buggy? 1 Answer

Camera Movement and angles 2 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