Hour 5 - The Sun Appears!
Created a simple Sun object which has a directional light attached and orbits around the island to simulate a basic day/night cycle effect. The player can also grab the sun and move it around manually, as well as "fling" it around. Just for fun!
Integrated the free LeanTween plugin to smooth out the "fling" interpolation. Nice and lightweight and really easy to use straight out of the box. Should continue to come in handy for future polish. Also added a CameraController with zooming via the scroll wheel.
Some Technical Notes
It took longer than expected to get the orbital rotation and related input logic working nicely because MATHS kept tripping me up. The final code ended up very simple, but I took a lot of detours getting there!
Unity's RotateAround achieves the basic orbiting, nice 'n' easy. Manually moving the sun is achieved by casting a ray into the scene from the cursor position and then finding the nearest point on the XZ plane along the sun's orbital path and snapping the sun straight there.
I tried doing this manually for a while but eventually got better results by just bunging in a great big invisible plane object on the XZ plane (on its own layer) that I could cast against directly.
When I get a hit against the plane I calculate the direction vector from the center of the island/scene/world to that point, normalise it, and then multiply by the sun's standard distance i.e. the radius of the sun's orbit. And voila, a valid orbital position for our sun.
Flinging the sun proved tricky due to having to work out which way to fling. Depending on which part of the "sky" the sun is in affects what input should translate to a clockwise or anti-clockwise rotation. I eventually used the change in angle (relative to the up axis) when the sun is being dragged to determine direction, and then adjusted the "fling" velocity accordingly.
Get Plantasia
Plantasia
Cultivate your own plant-covered island paradise!
Status | Released |
Author | Karn Bianco |
More posts
- Hour 240 - Plantasia Launches!May 21, 2018
- Hour 180 - Introducing New PlantsMay 03, 2018
- Hour 172 - What's That Sound?Apr 28, 2018
- Hour 160 - Preparing to go PublicApr 24, 2018
- Hour 94 - Savvy with SystemsApr 01, 2018
- Hour 78 - Expanding UniverseMar 11, 2018
- Hour 62 - Harvesting SeedsMar 08, 2018
- Hour 55 - Make It RainMar 06, 2018
- Hour 48 - Androids and SeedsMar 04, 2018
- Hour 38 - Warp Speed!Feb 24, 2018
Leave a comment
Log in with itch.io to leave a comment.