Search Unity

Draggable rigidbody2d very slow pushing other rigid bodies

Discussion in 'Physics' started by Darkwing Duck, Oct 25, 2015.

  1. Darkwing Duck

    Darkwing Duck

    Joined:
    Oct 1, 2015
    Posts:
    3
    Hi. I need help.
    I have two 2d rigidbodies with 2d box colliders. When I mouse down one (green on the image) I can drag it with spring joint 2d (frequency = 0). And dragging works fine. And when i try to drag green object through the blue object, blue object should be moved by green object with dragging velocity, but dragging is very very slow.
    Blue and green objects isKinematic value is false, gravityScale is 0, collisionDetectionMode is Continuous.
    I think the problem in joint, because when I set frequency to 1, all is good, but I don't need spring dragging. With HingeJoint2D the same problem.
    The velocity is 0,0 while dragging
    Untitled.png
     
  2. Darkwing Duck

    Darkwing Duck

    Joined:
    Oct 1, 2015
    Posts:
    3
    I achieved expected result by manipulating the velocity of rigid body.
    Code (CSharp):
    1. Vector3 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
    2. Vector3 direction = mousePosition - rigidBody.transform.position;
    3. Vector3 normalizedDirection = direction.normalized;
    4. rigidBody.velocity = normalizedDirection * Time.fixedDeltaTime * 15000;
    I think when I used SpringJoint2D with zero frequency the velocity was not calculating for draggable object.
     
    Last edited: Oct 25, 2015