C
C
ChelSiharpniy2022-04-10 15:48:08
C++ / C#
ChelSiharpniy, 2022-04-10 15:48:08

How to make objects not ignore colliders?

The problem is that I made a script to hold the object with the mouse, but .. when you drag it to any collider, it does not get stuck, it just goes through it, and sometimes the code sits right in the collider itself

:

void OnMouseDrag()
    {
        Vector3 mousePosition = new Vector3(Input.mousePosition.x, Input.mousePosition.y, distance); // переменной записываються координаты мыши по иксу и игрику
        Vector3 objPosition = Camera.main.ScreenToWorldPoint(mousePosition); // переменной - объекту присваиваеться переменная с координатами мыши
        transform.position = objPosition; // и собственно объекту записываються координаты
    }

Answer the question

In order to leave comments, you need to log in

3 answer(s)
G
GFX Data, 2022-04-10
@ChelSiharpniy

Try moving through a rigid body.

var rigidbody = GetComponent<Rigidbody>();
rigidbody.MovePosition(objPosition);

F
freeExec, 2022-04-10
@freeExec

objects did not ignore colliders

Do not change the coordinates by hand, this should be done by physics.

K
Kerim Rezai Shirazi, 2022-04-13
@judge971

add Rigidbody

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question