Object escapes outside when touched and dragged

Hi everyone,

I am new to Unity. I am trying to touch and drag my game object to some places in the screen. But sometimes when I apply more force, the game object is escaping outside out of bounding boxes and its losing its collision property. I don’t understand why it is happening ? Can anyone please help me with this problem…??? I am creating 2D game.
Thanks in advance.

The code that I used for touch and drag is,

**function Update () 
{
  if (Input.touches.Length > 0)
        {
            if (Input.touches[0].phase == TouchPhase.Moved)
            {
                var x = Input.touches[0].deltaPosition.x * Time.deltaTime;
                var y = Input.touches[0].deltaPosition.y * Time.deltaTime;
                transform.Translate(new Vector3(x, y, 0));                                
            }
        }      
}**

You arent moving the object with forces, you are teleporting it to a new location.

Collision isn’t going to stop that motion if the destination is not a colliding position.

If it IS a colliding position, it will teleport to there and then calculate a collision at that point, which might well force it to the outside of your arena depending on how far into the wall it is.

Short answer is if you arent moving something with physics then physics doesn’t apply to the move.