- Home /
Placing object in scene
Hello!
In Unity, I have a scene which has a texture that is a 360-degree picture, therefore the whole scene is set on the globe. Somewhere on this scene there is an owl. I want to move an object (cube) directly on this owl, so the cube will be in front of the owl. When I try to move this cube manually I am not successful because the cube is always placed somewhere near the owl but never just in front of it. How could I solve my problem?
Greetings
Answer by Ataraxxis · Jul 31, 2017 at 02:27 PM
Can you provide more information? What is the object that the picture is on (sphere, skybox) with which shader? Is the owl part of the 360-degree picture or an object itself?
Answer by borutkolar · Jul 31, 2017 at 02:37 PM
Picture is on sphere with Unlit/Texture shader. Owl is part of the 360-degree picture, it is not an object itself.
So to just have an object in between camera and owl you should be simply able to drag it there, though it was the main problem let's try to solve it mathematically.
Scale the sphere really huge and place an empty gameobject into the owl. This is now the owls position (we can't use the sphere position here).
calculate a vector that describes the line between camera and owl: (positionOfOwl - positionOfCamera) * x + positionOfCamera
Create any object and set it's position to the position the upper equation gives for x = 0.5 (so it should be halfway between owl and camera).
If you still don't see your object maybe look at your camera and rearange near/far clipping plane (or use a bigger/smaller scaling in scene).
And if this still doesn't work, upload your code please and share a link.
This isn't working for me. Position of my camera is (0, 0, 0). When I am on some zoo$$anonymous$$g I place the cube directly on the owl. But the problem is that then when I zoom in/out this cube it's no longer in the same position. I attached two screenshots - the first one shows how the cube is displayed in editor, the seconds one shows the cube when I am in play mode (cube is above the owl and is very small and red).
I don't know in which level you are understanding Unity, so first thing the view in scene is not based on your camera, in your pictures you have a different view angle. Also look if your scripts change something with your objects, note position, rotation and scale for the sphere, cube and camera and look if they change when entering play mode.
I am beginner in Unity but I know that the views in the editor and in the play mode aren't the same. I don't think the scripts change objects when entering in play mode. What I want to do is that when I move the phone (or cursor on computer in play mode) to the owl, the program plays sound of the owl.
I would recommend not putting the owl on the sphere, mostly spherical projections are used for the background (and only the background). What if you cut the owl, put it on a quad and use a script on this quad with On$$anonymous$$ouseOver()
. This way you have the mouse collision and owl position in one object. To fix the problem with the cube being displaced I would need the project, can't say where exactly the mistake is.
How can I cut the owl and put it on the cube? The owl is part of the picture. I can send you project source.
Your answer
Follow this Question
Related Questions
Moving an object with Clicking GUI Button 1 Answer
Moving A 2D Object Forward 1 Answer
360 cam live streaming questions 0 Answers
Equirectangular camera projection of a scene in Unity 0 Answers
Pitch limit of a ship 0 Answers