Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • CreatiCode
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo

CreatiCode Scratch Forum

  1. CreatiCode Forum
  2. Knowledge Base
  3. 3D Blocks
  4. Distance Constraint between 2 Physics Objects

Distance Constraint between 2 Physics Objects

Scheduled Pinned Locked Moved 3D Blocks
1 Posts 1 Posters 855 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • CreatiCodeI Offline
    CreatiCodeI Offline
    CreatiCode
    wrote on last edited by admin
    #1

    Introduction

    When you have enabled the physics engine in a scene, you can add constraints between objects. A constraint is a request that we give to the physics engine, and the physics engine will try its best to satisfy our request.

    For example, a distance constraint is a request that we wish to force the distance between 2 objects to stay the same no matter how they move.

    Note that the physics engine may not always be able to satisfy our constraint requests, so you need to test our program to make sure your constraint requests are realistic.

     
     

    The “Add Distance Constraint” Block

    To add a distance constraint, you can use the following block:

    86204618-755f-4190-9690-2d6b38cbba5e-image.png

     
    The first 2 inputs allow you to specify the first object from any sprite, and the next 2 inputs allow you to specify a second object from any sprite. Note that if one of these 2 objects is static (mass = 0), then you should specify that object’s name and sprite in the first 2 inputs.

    The last input is optional: it is the name of the constraint you are creating. If you need to remove this constraint later, then you need to refer to this constraint using its name.

    After this block runs, the physics engine will try its best to keep these 2 objects at the same distance as before this block runs. These objects can still move, but their distance will stay the same.

     
     

    Example

    In this program, we add 2 spheres A and B. Sphere A does not move, while sphere B can move freely. Sphere B is added at a distance of 200 to the right of sphere A, so after we add the distance constraint, their distance will remain at 200, but sphere B will be swinging around A due to gravity.

    5060cbf6-f2e4-4d85-82f9-39d24e2bcbf3-image.png

     
    Here is how it looks:

    r3.gif

     
     

    The “Remove Constraint” Block

    You can remove a constraint at any time using the following block:

    971d6711-1ced-4d83-bd81-b310d8b811be-image.png

     
    Note that this block requires you to input the name of the constraint to be removed.

     
     

    Demo

    Suppose we are running the example program above. If we click the “remove constraint” block while sphere B is swinging, then sphere B will start to fall freely:

    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/ba03511a-3399-4264-bbcf-b6ed9ce19c39.gif" width="900" style="border-radius: 5px; border: 1px solid #29622d;">

    1 Reply Last reply
    0

    Hello! It looks like you're interested in this conversation, but you don't have an account yet.

    Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

    With your input, this post could be even better 💗

    Register Login
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • CreatiCode