Question by
BinojBI · Jul 28, 2020 at 03:57 AM ·
scripting problemmovementrigidbodycolliderdrag-and-drop
Avoid overlapping drag & drop game objects in 3d space
Hi, I have searched numerous time how to avoid the draggable objects overlapping problem but I didn't get specif answer. Here is my problem. I develop a game which have function drag & drop to plane. once I drop the item It should be avoid to place another object same place. I have tried numerous ways which using rigid body & colliders. It should't work.
Here is object move function after place.
private void ObjectMove() {
if (Input.GetMouseButton(0) && currentSelectObjectSelected)
{
moving = true;
mousePos = Input.mousePosition;
Ray ray = Camera.main.ScreenPointToRay(mousePos);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, Mathf.Infinity, layerMask))
{
int PosX = (int)Mathf.Round(hit.point.x);
int PosZ = (int)Mathf.Round(hit.point.z);
Vector3 pos = new Vector3(PosX, LastYPos, PosZ);
Vector3 newPos = new Vector3(grid.GetNearestPointOnGrid(pos).x, LastYPos, grid.GetNearestPointOnGrid(pos).z);
//checkAnyobjectInPlace();
currentSelectObject.transform.position
= newPos;
}
}
}
Can anyone help me to check before place in this checkAnyObjectInPlace() method. @Legend_Bacon
Comment
Your answer
Follow this Question
Related Questions
How to fix this problem? 1 Answer
How to trigger a BoxCollider with a RigidBody? 0 Answers
Objects slowly move by their own? 1 Answer