- Home /
Put a camera inside a cube
I'm new to Unity and I'm trying to invent a game with 3d. I want to put a camera inside the cube object but how is it possible? I've read some forums and they mentioned about Normal. I don't want the camera to see the outside of the cube. I want the camera to be inside the cube, so that the only part that will be seen in my game is the inside of the cube. Is it possible? Please help me. Thank you in advance!
Im using unity. I have no idea on how to use blender. Where can I find the normals face? Is it through code or in the inspector panel? Please help me. Thank you!
Unity is a game engine - you can't create or edit models in it (well, not anything more than a basic primitive). To create models to use in your game, you need a modelling program. I said Blender because it's free, but 3DS $$anonymous$$ax or $$anonymous$$aya are alternatives.
You can use the ReverseNormals script in the Unity Wiki to reverse the normals of an object. The result will only be seen at runtime using this script.
Answer by fafase · Jul 05, 2014 at 09:35 AM
Just put it inside, the cube won't show since the normal you read about makes the inside of the cube not rendered.
If you really want to make sure, just increase the near clip plane value of your camera.
Sometimes you may simply want to try since it takes about 5s to figure out that inside of the cube the camera won't render it.
I really want to get inside the cube. When I tried to put the camera inside, it's not working.
If you use the cube from Unity they already use backface culling, which means only one face of the cube is rendered, the outside one. Just place your camera inside of the cube, same position and see it for yourself.
Answer by tanoshimi · Jul 05, 2014 at 09:36 AM
Cameras only see objects if their normals are facing them. So, if you want to be inside a cube, you need to make sure all its normals face inwards (generally they face outwards). This is easy to do in a modelling program like Blender.
You're trying to say that I'm going to create a cube in blender then edit the normals face in blender? Then put it to unity? Am I right?
Yes, exactly. And please don't post comments as answers. Post them as comments (click the "Add new comment" button to the right)
Okay. I'll try to create a cube in blender then find the normals and by the way thank you for telling me about the comment! I'm not aware that it's really different. Thank you!
Is it possible to set the size of the imported cube from blender to unity using script? Just like setting the size of the cube?
Yep - just adjust the scale. https://www.dropbox.com/s/p7mdzxsjmooolxj/inwards_cube.fbx
Answer by Kiwasi · Jul 05, 2014 at 10:46 AM
If you need a really dodgy cube and you don't want to go to blender, just build the walls of your cube out of planes. That's how my first game was built. I wouldn't suggest trying to learn Blender and Unity at the same time.
I think it's not possible, because what I'm trying to do is also to set the size of the cube, and i don't know if it's possible if I'm going to use planes.
Certainly possible to resize a cube made with planes, just a bit more work. But not as much work as learning 3D modelling.
If you hang around for a while you will learn that none of my answers are impossible. Some might not be good ideas, but they are certainly all implementable.
How will it be possible? :( because I'm trying to resize the cube through a script.
Its a multi step process as follows. You can figure out the details yourself.
Calculate the dimensions of the cube on the new scale
Scale each plane to the appropriate scale
$$anonymous$$ove each plane out (or in) to the appropriate position
You can also do the same with primitive cubes if you want some thickness to your walls.
parent the 6 planes used to create your cube to an empty object placed at the center of the cube, scale the parent. No need to scale each faces
Answer by Klarax · Jul 10, 2014 at 03:18 PM
According to the community scripts. And will only flip the normals when in game mode, not in editor. Worth a go
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(MeshFilter))]
public class ReverseNormals : MonoBehaviour {
void Start () {
MeshFilter filter = GetComponent(typeof (MeshFilter)) as MeshFilter;
if (filter != null)
{
Mesh mesh = filter.mesh;
Vector3[] normals = mesh.normals;
for (int i=0;i<normals.Length;i++)
normals[i] = -normals[i];
mesh.normals = normals;
for (int m=0;m<mesh.subMeshCount;m++)
{
int[] triangles = mesh.GetTriangles(m);
for (int i=0;i<triangles.Length;i+=3)
{
int temp = triangles[i + 0];
triangles[i + 0] = triangles[i + 1];
triangles[i + 1] = temp;
}
mesh.SetTriangles(triangles, m);
}
}
}
}
I tried to put this script as a component of my gameobject cube, but nothing happened. Why? :((