I've made a scene full of half transparent cubes. On the inside of each cube, there is another (slightly smaller) cube with the mesh flipped so the walls of the cube are visible from both the inside as well as the outside. My problem is that the ordering of the cubes isn't correct. If I look around with the camera while the game is running, the order of the cubes starts to jump around. As you can see in the images, the gray cube in the top left is jumping back and forth.
I'm using the 3rd Person Controller + Fly Mode as my player controller. All cubes are using the Standard shader. Also worth mentioning is that the cubes and corresponding materials are generated from a C# script.
This is done for each cube to enable transparency:
material.SetFloat("_Mode", 3f);
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
material.SetInt("_ZWrite", 0);
material.DisableKeyword("_ALPHATEST_ON");
material.DisableKeyword("_ALPHABLEND_ON");
material.EnableKeyword("_ALPHAPREMULTIPLY_ON");
material.renderQueue = 3000;
I've tried setting the camera to Camera.transparencySortMode = TransparencySortMode.Orthographic because I found this as a tip in the forums, but this made the matter worse.
Actually I was expecting this to just work out of the box. But it seems I have to do something special to get my use case to work. But what? :)
Related
I'm making a game where I move a red cube across a plane with arrow keys (I am setting the velocity in order to get a constant speed) Here is a preview:
game
Currently, I am just using a plane with a grid material/texture. However, I wanted to change one of the tiles in this grid to a different color and detect when my cube passes over it.
My idea was to simply replace the plane with a bunch of quads. However, when I do that and try to navigate my cube across the quads, it seems to collide with the side of the quad and flip up, despite the fact that they are all at the same height and positioned right next to each other.
Is there a way to make the quads flush so when I push my cube over it, it won't collide with the side of the quads? Is there a better way to create this behavior?
You can disable colliders at this quads and add invisible big plane with collider
I'm looking for ways to clip an entire unity scene to a set of 4 planes. This is for an AR game, where I want to be able to zoom into a terrain, yet still have it only take up a given amount of space on a table (i.e: not extend over the edges of the table).
Thus far I've got clipping working as I want for the terrain and a water effect:
The above shows a much larger terrain being clipped to the size of the table. The other scene objects aren't clipped, since they use unmodifed standard shaders.
Here's a pic showing the terrain clipping in the editor.
You can see the clipping planes around the visible part of the terrain, and that other objects (trees etc) are not clipped and appear off the edge of the table.
The way I've done it involves adding parameters to each shader to define the clipping planes. This means customizing every shader I want to clip, which was fine when I was considering just terrain.
While this works, I'm not sure it's a great approach for hundreds of scene objects. I would need to modify whatever shaders I'm using, and then I'd have to be setting additional shader parameters every update for every object.
Not being an expert in Unity, I'm wondering if there are other approaches that are not "per shader" based that I might investigate?
The end goal is to render a scene within the bounds of some plane.
One easy way would be to use Box Colliders as triggers on each side of your plane. You could then turn off Renderers on objects staying in the trigger with OnTriggerEnter/OnTriggerStay and turn them on with OnTriggerExit.
You can also use Bounds.Contains.
In Unity 3D I make GameObject → 3D Object → *Cylinder. And this cylinder has the components: Cylinder (Mesh Filter), Capsule Collider, and Mesh Renderer. I can add the last two components to my exported cylinder from Blender, but I can't add the Cylinder (Mesh Filter) component. What is Cylinder (Mesh Filter)? Is it just a Mesh Filter component?
Now I have some problems. I created some Cylinders in Blender. All of them I did using Knife Project. And the last step was to click on Delete → Faces. If I'm not clicking on Delete and make delete faces, it will not cut the hole.
The first problem is in the first cylinder I created in Blender. I cut a simple circle hole, and it's working fine exported it to Unity 3D. But the next cylinders I exported for some reason, when I'm looking at them from the front, are hollow. I see the other side outside, but if I'm moving around from the back, it's not hollow. I am not sure why.
In this screenshot are the cylinders I exported and they are in Unity 3D. The one that is fine is on the left. The others on the right hollow like. The hole cut was to the other side, but if I will look from behind, it's not open in the back:
Back:
The cylinders on the right I changed the circle. The one on the left I didn't change; it only rotated it.
My main goal in the end is to create a cylinder in Blender with just a hole I can walk inside with my character in Unity 3D.
The on the left seems fine, but the hole is too small and high, so I can't walk in.
In Blender it looks fine only in Unity. It looks hollow side to side from the front:
The problem is not the normals.
Unity does not render backfaces. Faces have front and back sides, and game engines don't render back sides by default for optimization reasons. Your mesh is not watertight, and from the hole you are seeing the back side of the faces of the other side.
The first cylinder looks fine, because it has volume, so it's watertight and its backfaces are hidden inside it.
Solution 1: in Unity, set the cylinder's material as double-sided. This will tell Unity to not disregard backfaces that use this material.
Solution 2: in Blender, extrude all faces of the cylinder a bit so that it has some volume to it. This way, the mesh will be watertight, so there will be no backfaces visible (backfaces will be hidden inside the model).
Regarding collision problems;
if you want a character to be able to walk inside the cylinder, but not through its walls, do solution 2 and put a "mesh collider component" on the cylinder in Unity. This will make each face collideable instead of wrapping a simple 3D object around the model as the collider.
You simply need to flip your Normals in Blender. That is the reason you are seeing this effect in the whole of your cylinder. Follow this tutorial for the inside faces of your cylinder.
I'm struggling to find any simple/up to date tutorials on how to make my own skybox for Unity. I want the skybox to be cartoony/vector based so preferably I would like to make it in Adobe Illustrator.
How do I do this? Could anyone direct me to any tutorials? Also, are there any programs that allow you to upload an image that generates a skybox for you?
Thanks!
You may create a new "Skybox/6 Sided" material, and asing it instead the default skybox material. It's the same principle, a cube with 6 images that correspond to each side "front, back, up, down, left, right".
You have to generate a cubemap to have a skybox object, young padawan.
From the Unity Manual:
http://docs.unity3d.com/Manual/class-Cubemap.html
A Cubemap is a collection of six square textures that represent the reflections on an environment. The six squares form the faces of an imaginary cube that surrounds an object; each face represents the view along the directions of the world axes (up, down, left, right, forward and back).
Cubemaps are often used to capture reflections or “surroundings” of objects; for example skyboxes and environment reflections often use cubemaps.
I'm currently working on 3D insects in Unity, and I want to create a material that mimics the way the mantis or the damselfly eyes behave, especially the little black spot in the middle. For the moment I have a very fine material that makes everything I need, but the reflection cubemap I use for the blackspot is aligned with the world axes by default. Which means that the black spot will only move when I move the object, but in my project only the camera is moving.
Hence my question, is it possible to align the cubemap with the camera's axes, so that when I move the camera, the "front" of the cubemap stays in front of the camera, and so on?
PS: I haven't really messed with shaders yet, so perhaps I just need a line of code or something, please feel free to write it!