Object moving to bad position

Hey! I was making simple inventory in unity, with draggable objects. Unfortunately my inventory item moves to different position than I wrote in the code, I thought it’s because mouse position is bad, but even when I wrote new Vector2, object is moving to different pos? Can anyone say why?

Sounds like you wrote a bug… and that means… time to start debugging!

By debugging you can find out exactly what your program is doing so you can fix it.

Use the above techniques to get the information you need in order to reason about what the problem is.

You can also use Debug.Log(...); statements to find out if any of your code is even running. Don’t assume it is.

Once you understand what the problem is, you may begin to reason about a solution to the problem.

If you still cannot figure it out, try this template to report technical issues:

How to report your problem productively in the Unity3D forums:

http://plbm.com/?p=220

This is the bare minimum of information to report:

  • what you want
  • what you tried
  • what you expected to happen
  • what actually happened, log output, variable values, and especially any errors you see
  • links to actual Unity3D documentation you used to cross-check your work (CRITICAL!!!)

The purpose of YOU providing links is to make our job easier, while simultaneously showing us that you actually put effort into the process. If you haven’t put effort into finding the documentation, why should we bother putting effort into replying?

You tagged this 2D physics so can you please elaborate on how you’re using 2D physics.

Thanks for help, after some time of debugging I found out that changing pivot of object can prevent it from changing position. The only problem is that I still don’t know what caused it.

So you’re not using 2D-physics?