#Moving game objects with a mouse

1 messages · Page 1 of 1 (latest)

odd garnet
#

I tried and tried again but can't seem to make it work - the raycast does detect the gameobject, and the code detects the mouse button being pressed as well. Shouldn't it technically be working? I'm so confused.

void Update()
    {
        RaycastHit hit;
        Ray ray = cam.ScreenPointToRay(Input.mousePosition);
        LayerMask mask = LayerMask.GetMask("PhysicalObject");
        if (Physics.Raycast(ray, out hit, Mathf.Infinity, mask) && Input.GetMouseButton(0))
        {
            hit.transform.position = new Vector3(cam.ScreenToWorldPoint(Input.mousePosition).x, 1, cam.ScreenToWorldPoint(Input.mousePosition).y);
            Debug.Log("hit");
        }
    }```
hasty pollen
#

Which part does not work

flint bolt
#

Didn't you say you already suspect the problem because you are losing raycast when moving?

#

Test that

flint bolt
#

You still might have to lock up OnDrag event untill released

flint bolt
odd garnet
#

oh shit

#

bing ai wrote the code for me