Hi guys, i got this script which give me possibility to move item in front of my character - but i have two problems, hope you can help me with it ![]()
First, when im holding item, it can go through walls and other item, how can i fix this?
Seond, can i make some improvment to increase distance when character can grab item?
Sorry for english by the way ![]()
And here is the code (very simple)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class draggableitem : MonoBehaviour {
Vector3 dist;
float posX;
float posY;
void OnMouseDown()
{
dist = Camera.main.WorldToScreenPoint(transform.position);
posX = Input.mousePosition.x - dist.x;
posY = Input.mousePosition.y - dist.y;
}
void OnMouseDrag()
{
Vector3 curPos = new Vector3(Input.mousePosition.x - posX, Input.mousePosition.y - posY, dist.z);
Vector3 worldPos = Camera.main.ScreenToWorldPoint(curPos);
transform.position = worldPos;
}