I am currently working on making a game where the player has to warn a village of onecoming lava, so I need a way to make the lava move in a downward direction along a trench in the terrain. How can I do this?
I’ve never made a game before in Unity so I need a bit of help.
If it’s a simple trench going in a single direction, just a tilted lava object moving on a path should do the trick. Depends as well on what the player will and wont be able to see too.
Lava could be hard because its close to fluid, but fluid simulations are expensive.
The simplest way would be to have a small lava object, that you scale and translate down the mountain so it looks like the lava is moving closer. Then adjust the texture repeat settings to keep a uniform size of the lava texture. The problem with this, is it will not be able to conform to the shape of the terrain well, and you might not get the most realistic flow. An easy way to fix the flow would be to also offset the texture as the lava is flowing to make it look like it is pouring. This way would give you quick results and a raised lava, but would likely look the worst. And, the lava would only flow in a straight line.
Another way, would be to use a realtime mesh deformation, but that might be complicated to implement and you said you have never used Unity before. This might be the hardest and most performance heavy, but would be the closest you can get to a fluid simulation.
A semi-complicated way would be to write a fragment program that lerps a second texture (the lava) based on a mask texture. Then you can offset your lava texture to get a flowing effect. I think this would be the best compromise of time and knowledge and results. It requires some CG knowledge, but most shaders start out the same way and share a large part of the actual commands.
The last option I can think of might be to use some particles and a particle collider to keep them in the trench. That might work well with some tweaking and good textures. If you are just getting started with Unity and programming, then this might be the best way, or depending on how your trench looks based on depth width etc.
And, when Unity 3 is released, you will have some more options. Soft bodies may do what you want, and surface shaders make it easier to write shaders.
Hmm… seems like any way I do this, it’ll be really complicated…
I also have Blender, and am a bit more skilled in that. Blender has fluid simulation. Would it be possible to create an object in Blender, apply fluid simulation to it, and import it into Unity to be the lava?
Hmm, I don’t know. If you can bake the fluid animation into bone based animations than yes, otherwise, no.
Since you know Blender, This would not be overly complicated. Model the surface of your lava so it lines up with your trench. Create a Gradient texture that starts as opaque and moves all the way down to transparent at the bottom of the hill. Then use a Transparent shader in Unity and adjust the cutoff value so that the lava will slowly appear. That is a simple script. If you choose this idea, I’ll help you get started.
Then, here is the only somewhat difficult part. Create an end cap mesh piece. so that the player cannot see under your lava. Then, in Unity, create a script that using Waypoints and rotation, will have the end cap move down the trench with the rest of the lava. That would take a little work, but is not that hard, once you work with it for a little while.
So you would have 2 meshes, a surface, and the tip of the lava. You would slowly adjust the alpha cutoff so that the lava appears. Then you move the end cap down the hill with the lava so it has a front.
P.S. I actually like how this idea sounds now that I’ve finished writing it.
Edit: If you need to see your terrain in Blender to model it right, see this.
The frustrating thing is I was looking into something like that only last week. Unity would have had absolutely no problem in loading and replacing meshes generated by Realwave to give the impression of perfect fluid effects (even if it’s always going to look the same each time that part ran), the only problem though would have been the number of meshes required to pull it off. Other than that it would have worked brilliantly for set scenes where you want complete control over things like lava running through a trench and so on.
This will sound really nooby, but how can I model a lava model in Blender to be the same size and shape as the trench inUnity? I have no way to view the image of the trench side-by-side with the lava I’m modeling, and I’d like to somehow display the image in Blender so I have a template to follow.
Let me re-phrase the auestion. Keep in mind that I pretty much ignored everything on the 3rd page of my other thread where you were arguing with that other guy.
Should I save the code in a .txt file in the Editor folder in the Assets folder of my game?
Don’t assume that I have any clue what I’m doing. Please. It’ll make things a lot better for both of us.
Don’t worry, there’s no danger of me assuming you have a clue what you’re doing, I can promise you that.
And no, you want to create a new javascript file and copy/paste it into that, then save, make sure no errors appear once it’s compiled. Close and restart Unity and the new menu item should appear at the top. Make sure your script is named correctly as is mentioned on that wikipage, and that it’s placed in Assets/Editor or it wont work.
Then when you’ve created your terrain, use it to export to an .obj file. Choose half for it’s res, or less depending on how powerful your computer is, because terrain exports tend to be huge regardless, and you only need a basic copy of it to work from.