We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.

Pick up object and throw

Home Forums General Questions Pick up object and throw

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • #57075
    andrei pek

    Hei everyone!

    So for the pas few weeks I’ve been trying to make a physics app where you thow an object by click and hold/ tap and hold and throw it in the direction of the mouse/finger movement.

    Anyone did something similar or can help me out with this? Any help is apreciated.

    I went over the defaul physics app but nothing from there is similar to pick up and throw.

    Any help is apreciated, take care!


    andrei pek

    So I managed this much,
    Pick up the cube, move it and once I let go it adds a random rotation.
    Any way that I can make it go in the direction I drag my mouse/finger for mobile)?


    You must be logged in to view attached files.


    You can switch the cube’s body type between dynamic and kinematic when dragging. Kinematic means that user actions (or animation) are taken into account by the physics engine. So, if you make the cube kinematic at the start of the drag then by the end it will have its velocity vector set according to how the cube was being moved. But after that the cube should be switched to dynamic, so it will be fully controlled by the physics engine again.

    Such puzzles setup can look like this:

    But dragging by mouse can be inconvenient. It’s an instant movement, so the resulting velocity can be too large. The solution is to copy the current velocity vector, then set the cube’s velocity to zero and then apply a modified (normalized, scaled, etc…) velocity vector to the cube, so it will move in a more controlled manner:

    Here’s the example: throw.zip

    You must be logged in to view attached files.

    Co-founder and lead developer at Soft8Soft.

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.