Google hasn’t answered my question so I’ll try here. Everything works fine but dragged object goes through walls. I have tried many ways to solve this but none of them works. I tried using OnTriggerEnter on walls, Overlapshere on dragged object to detect collision but can’t get any of them work properly. I shortened the code a little so I hope i didn’t remove anything important. Here is the code:
void OnMouseDown()
{
mZCoord = Camera.main.WorldToScreenPoint(gameObject.transform.position).z;
mOffset = gameObject.transform.position - GetMouseAsWorldPoint();
}
private Vector3 GetMouseAsWorldPoint()
{
Vector3 mousePoint = Input.mousePosition;
mousePoint.z = mZCoord;
return Camera.main.ScreenToWorldPoint(mousePoint);
}
void OnMouseDrag()
{
if (canpickup)
{
rb.MovePosition(GetMouseAsWorldPoint() + mOffset);
rb.isKinematic = true;
}
}
void OnMouseUp()
{
rb.isKinematic = false;
}
void Update()
{
float minDist = 2;
float dist = Vector3.Distance(Player.transform.position, draggedobject.position);
if (dist < minDist)
{
canpickup = true;
}
else
{
canpickup = false;
}
}
Pretty simple but can’t understand the physics element here which I think is the problem.
Thanks for help!