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
    Posts
  • #57075
    andrei pek
    Customer

    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!

    Andrew

    #57085
    andrei pek
    Customer

    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)?

    https://gyazo.com/c67d54147e09c4219a5ceed86f5e6786

    Attachments:
    You must be logged in to view attached files.
    #57124

    Hi,

    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:
    physics_puzzles.png

    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:
    physics_puzzles2.png

    Here’s the example: throw.zip

    Attachments:
    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.