I am currently working on a project where I would like the player to be able to “grow” or “create” or “spawn” the level as they travel through it.
The only source of light in the level is a spotlight directly above the player. As the player runs, the radius of the spotlight grows larger and anything within the lights radius will “grow”. For example, if you were running through a forest, plants and trees would be growing right before your eyes–completely based on the fact that YOU (the player) are moving and causing the creation.
So my question is:
What is the best way to go about achieving this?
I have tried using set-driven keys in Maya, but Unity does not seem to be able to read them. I have also considered keyframing each object twice (one key below the earth, one key above the earth).
I’m thinking maybe a custom script in Unity is the way to go. Any ideas? All information is greatly appreciated. Thank you!
I’ve added a .JPEG of how I see this level function as the player moves across the landscape.
Instead of just lifting the plants vertically out of the ground, also scale them from 0 to 1. Each plant could even have a different ‘grow speed’. Maybe even use Lerp to get a fast initial grow that slows down as it is almost finished growing.
I think the best way is to use a script, not sure how familiar you are with javascript, but it would be the best way.
Create each unique plant as a prefab.
Attach your ‘grow_plant.js’ script to each prefab.
Place the prefabs below the ground in Unity instead of in your 3d Modeling program.
Not sure what the best way to trigger the StartGrowing function is. Lots of options.
Attach a sphere trigger collider to the spotlight. Attach colliders to the plants. Use the OnTriggerEnter on the spotlight to tell the plant to grow. (Bonus, you get an OnTriggerExit funciton too)
Each plant could check it distance to the spotlight relative to the radius, then trigger its own grow when necessary.
I think I like the 2nd option most since I think it would do less unnecessary polling/update logic.
Lots of stuff you could do. Could even extend the script to cause things to ungrow as you walk away from them.
I like the idea of having them scale from 0 to 1 instead of just popping out from under the earth. I will test out the information in the links your provided. Thank you =)
However, I have thought of a new problem…My plan is to create custom objects (trees, rocks, bushes, etc) and mass place them using Unity’s Terrain Editor/Tree Placement tool. So here’s my new question:
Is it possible to “grow” anything that I’ve “Mass Placed” using Unity’s terrain editor?
If growing Mass Placed objects is not possible, I would have to individual place every tree, bush, rock, etc…this would cause the game to lag since my environment is one huge level–not to mention how much extra time it would take
Any ideas? Any and all information is greatly appreciated. Thanks!
You won’t be able to grow objects that have been placed with the terrain editor, but to do something similar to save time, export the height map to photoshop, then using some different colors to represent different objects (same as the splat maps for terrain textures) paint your terrain in PS. Then use the image as a Texture2D and populate the world on load with the various objects using a simple javascript to read pixel colors from the image. Or just populate the world in the area of the player to save some load time.