Snapping while dragging 2D object
Hi,
I'm trying to create a "snapping" effect while dragging a game object trough the screen. I tried to round the object with:
transform.position = new Vector2(Mathf.Round(transform.position.x), .Round(transform.position.y));
Tried on OnMouseDrag() and Update(), but there's no effect happening on screen.
The effect that I want is similar to this from Ultimate Chicken Horse: https://youtu.be/tWhPbRbLmnw?t=21 (couldn't find a better video). The video starts exactly where you can see the mouse moving and the object snapping in the background.
Am I missing something?
Are you sure that rounding to a whole is enough? Seems like you need to round to larger values.
huum I think is enough, when the On$$anonymous$$ouseUp is executed, I round the same way to put the object in exact coordinates.
$$anonymous$$y game is very "grid" based, so each point of the grid, like (0,1) or (1,0) is a 'unit' on Unity and has block/image. if that makes sense.
Does transform refer to the dragged 2D object? Is it working at On$$anonymous$$ouseUp?
Your answer
Follow this Question
Related Questions
Drag and Drop Problem 1 Answer
copy file path into input Field with drag and drop 0 Answers
Snap objects back to their original place 0 Answers
2D Drag and Drop, but not when slot is already full 0 Answers
Collider not working properly 0 Answers