- Home /
Procedural Object creation + Animation (language 'any') + video link
How would I proceduraly duplicate an existing object in the scene and apply procedural animation to it using just math. I would like for this to be done in c# if possible. but if its easier or someone has a solution for it in another language I'm completely open to it.
If anyone is able to supply a solution feel free to make it super simple.
I have a sphere in the scene and I want to proceduraly duplicate and apply animation to that referenced sphere. The animation itself would be moving the sphere from a random starting point within a 10x10 grid, to its ending point which would be 10 units up(Z-axis) over the course of a half a second. I really hope this is a possible think and that guys can help me out.
example = http://www.youtube.com/watch?v=-CTmD5vrHSg&feature=youtu.be
Thanks John
Answer by Mortoc · Jul 18, 2012 at 07:27 PM
It is very easy to copy any object. Use UnityEngine.Object.Instantiate
You can also procedurally move things around very easily in unity: "GameObject.transform.position = someVector3;" You can change "someVector3" per frame and make it follow any sort of math you want. Unity's Coroutines make functions execute over a time in a way you can procedurally control, I'd say give them a try, it'll give you a good idea how to do this.
How do I specify where these objects are to be created. Can I somehow place spawn points in the scene and use those as the points in which the spheres will be instanced to as their starting positions?
Yes, you can do that. If you follow the getting started with Unity tutorials, by the time you're done, you'll have no problem doing this sort of thing.
http://docs.unity3d.com/Documentation/Images/manual/ScriptingTutorial.pdf
Would you be able to help me mock up just a quick sample of how this is written. I'm new to unity and this is my first build of any kind so any examples would be greatly appreciated. I understand what I'm after but I'm not quite sure how to write these things. The more examples I see the more I'll be able to take it from there and go crazy. I'm familiar with the concept of scripting as I've done my fair share in 3d applications like 3ds $$anonymous$$ax and $$anonymous$$aya, but not unity.
These are the steps I'd like to see how would be written together and from there just explain how a fresh new scene would be setup. I created a sphere and a new js script but I'm not sure where to place the script, and does the object being duplicated have to be in the scene or just in the project?
Steps: 1. Using Instantiate to duplicate a GameObject 2. Give the new instanced object a unique name 3. Using an array of predefined locations in 3d space place the newly duplicated object. (these locations could be defined by using spawn points? if possible) 4. Apply a simple procedural animation to the object over the course of 10 frames.
Where is the location of that tutorial. I was going to see if there were more scripting ones in that same level of detail. It definitely helped make sense of some stuff.
AWESO$$anonymous$$E! Great news. So from the linked pdf I've been able to do steps 1 & 3. Now I'm trying to figure out how to apply a procedural animation to the objects. I do not have to bother doing the unique name since I'm just instantiate a prefab....correct?
Thanks again for you help. It's been super helpful.
Your answer