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. 2D Blocks
  4. Fixed Relative Position Constraint in 2D Physics

Fixed Relative Position Constraint in 2D Physics

Scheduled Pinned Locked Moved 2D Blocks
1 Posts 1 Posters 795 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 are using the physics engine in your 2D project, you can add “constraints” to objects, and the physics engine will try to enforce these constraints.

    One such constraint is “fixed relative position”, which tries to keep the relative position from one object to another the same. You can think of these 2 objects as one compound object when this constraint is in effect.

     
    To add such a constraint, you can use the block below:

    f46793f6-ee18-449b-b379-35a912ad97dc-image.png

     
    This block is very easy to use, since all that you need to specify is the other sprite. Both objects need to have been added to the physics world before this block is used.

     
     

    Example 1 - At Least One Object is Fixed

    When one of the 2 objects is “fixed”, then the other object will also be fixed at its position. Otherwise, the relative position between these 2 objects won’t stay the same.

    In this example, there are 2 sprites “ball 1” and “ball 2”.

    “ball 1” is fixed at the position of (0, 0):

    468d9a73-5f17-45a8-a91e-484afcb786d6-image.png

     
    “ball 2” is a dynamic object, but we are requesting that it keeps the same relative position to ball 1, so it would not fall due to gravity:

    87fe50da-4ee5-44d5-a3b0-2017df51cd29-image.png

     
    If you switch ball 2 to fixed and ball 1 to dynamic, the result is the same.

    a89df6a4-aa24-437e-94a8-c75bda11f686-image.png

     
    Here is the project link:

    https://play.creaticode.com/projects/807555715f43e2d84b9681ec

     
     

    Example 2 - Both Objects are Dynamic

    If both objects are “dynamic”, they may fall due to gravity, but their relative position stays the same.

    In this project, we add a fixed box as well, and the 2 balls stay in the same relative position even when they collide with the box:

    v1.gif

     
    Here is the project link:

    https://play.creaticode.com/projects/c39685af2d5e5db422260ea0

    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