- Home /
2D coordinate grid over a 3D scene?
Fairly new to Unity, having a hard time figuring this out. I have a 3D scene where users can drag objects from a menu onto that scene. I'd like to implement a grid (either invisible or visible) where these objects would stick on to, but I'm not sure how I would go about adding a 2D grid to a 3D scene.
I was thinking about using a separate orthographic camera but only making this gird "layer" visible to it, but I'm not sure how to best tackle this. I've only been working with Unity for about two weeks so I'm still in noob territory.
Answer by e-bonneville · Jun 20, 2011 at 03:17 PM
Just constantly round the coordinates of the objects you're dragging. That'll snap them to a 1x1x1 grid. If you'd like to overlay a visible grid on the screen you can either use a GUI texture or a separate orthographic camera.
Thanks, but how I actually move an object with 2D coordinates in a 3D scene?
Ok, so I have this 3D backdrop with a perspective camera, but I want the user to be able to click and drag an object in a 2D space (x and y, no z). When the user is done setting that object's position, I'll then get the 3D coordinates using ScreenToWorldPoint, but it's the first part I'm stuck at.
Answer by GTaveira · Jun 20, 2011 at 07:57 PM
My first thought was to create a plane collider and place it wherever you want it to be. Then, you could cast a ray from you mouse screen position and get the point where the ray hit the collider. You would assign your object Y-axis based on that point. That way you could freely move in 2D and your object would be snapped to the grid.
Answer by dentedpixel · Feb 13, 2012 at 12:40 PM
To find the 2d coordinates of an object on the current camera you can use this function Camera.WorldToScreenPoint
Your answer
Follow this Question
Related Questions
Arrange objects in a box formation? 1 Answer
How to make 2d distortion? 2 Answers
Get position from Isometric TileMap 1 Answer
parallax scrolling using orthographic camera 1 Answer
play sound while at certain coordinates of map (javascript) 1 Answer