- Home /
Snap objects together (Ingame)
I'm trying to snap objects togheter ingame with horrible results.
This is my scenario: (http://i59.tinypic.com/24e4cb9.png)
Every object (including floor) has a Box collider, they don't have rigidbody.
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
float dist = 100;
RaycastHit Hit;
Vector3 targetPos;
if (Physics.Raycast (ray, out Hit, dist))
{
if (Hit.collider.gameObject.tag == "Floor") {
targetPos = Hit.point;
targetPos.y += Hit.collider.GetComponent<Renderer>().bounds.size.y;
selected.transform.position = targetPos;
}
}
¿How can i fix dis overlap between the objects? I just want to place them on floor top or over another object top.
Comment
Your answer
Follow this Question
Related Questions
Can't get a laser working properly. 2 Answers
How can I make diagonal collisions work with raycasts from a boxcollider? (3D, C#) 0 Answers
Character Controller can pass through Collider 1 Answer
Raycast not working on object without gravity 0 Answers
Destroy objects within ordered Array by line of sight 1 Answer