Trying To Snap Gameobjects Together For A Buildsystem

Hi, i am building a building system and i have Ghost floors and normal floors right now i wan’t to detect if there is a normal wall in the scene then depending on where the mouse pointer is looking i wan’t the ghost floor to snap to the edge of the normal floor. Can some please help?

-Thanks Nicholas

You should be able to use this tutorial series and adapt it to your game I would have thought, it’s the same sort of system.

Thankyou for the suggestion but it was not what i was looking for. Do you have any other suggestions

Are you talking about achieving the actual effect of a ghost effect on what you’re placing in the scene? It depends on how you want to do it but for the effect itself you’re just instantiating in the floor with a transparent material. You then do a check for a click and then use the code provided in the tutorial to snap the gameobject to position.

For the ghost gameobject to work you just need to remove the rigidbody and collider, the ghost gameobject follows a raycast every frame in most cases.

Oh i see what you mean thank you i will try it later.

-Thanks Nicholas

Also do you know how to make the ghost wall follow the mouse? cause that would help a lot.

-Thanks Nicholas

To make the gameobject follow the mouse you’d just use a standard hit.point raycast and have it follow the raycast using update, if you want to have your ghost appear only at certain times you can do things like setup some buttons that instantiate the ghosts at your mouse position when you click them.

There are plenty of tutorials out their on how to to do raycasts, specifically you want your raycast to look for hit.point and that should do the trick, hope it helps.

Thankyou very much!

Hi i cannot find any tutorials could you please help me?

https://www.youtube.com/watch?v=izxLqJDwpBg

This is the right sort of code, in order to have it work the way you’re wanting you should have the raycast fire off when you press a UI button and rather than put the raycast into a mouse click you should put the code into the Update function so it happens every frame as you are moving the mouse along the ground.

Oh before I forget, this is actually quite important, in order to prevent the object going halfway into the ground like the video, you should make it so your raycast fires at an empty underneath whatever prefab or gameobject you intend to spawn into the game on the ground this will prevent intersecting problems. So to do this, when you get the raycast code set up you should make the gameobject you’re spawning a child of the empty and then that empty will take care of the positioning and placing rather than the gameobject itself.

The raycast fires directly into the centre of any gameobject which is why this issue happen, I won’t write code out for you, that’s your job, but you should have everything you need here to work it all out.