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. Set Rotation Axis in 2D Physics

Set Rotation Axis in 2D Physics

Scheduled Pinned Locked Moved 2D Blocks
1 Posts 1 Posters 837 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 “set as rotation axis”, which sets another sprite as the rotation axis of the current sprite. The current sprite can not move further away or closer, but can rotate around the axis object.

     
    To set another sprite as the rotation axis, you can use the block below:

    21330827-09ee-4c23-b85f-28faa22758e4-image.png

     
    This block accepts 3 input parameters. The first input is the target sprite to be used as the rotation axis.

    The next 2 inputs allow us to set the position offset in the X and Y directions. When these 2 inputs are both 0, the rotation axis will be located at the same position as the target sprite. For example, if the target sprite is at x of 100 and y of 30, then the rotation axis will also be at x of 100 and y of 30.

    However, we can change the location of the axis by adding offsets in the X and Y directions. For example, if the x offset is 20, then the rotation axis will be at x of 100 + 20 = 120.

     
     

    Example 1 - The Target Object is Fixed

    The most common way of using the “set rotation axis” block is to have a fixed target object as the rotation axis, so the current sprite would rotate around that object.

    In this example project, there are 2 sprites: “blue ball” and “yellow ball”.

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

    a45fbcd1-c4c2-4bbd-bed1-4a26c541f1d4-image.png

     
    “yellow ball” is a dynamic object, but we only allow it to rotate around the blue ball, so when it falls due to gravity, it starts to rotate around the blue ball.

    1d5dd39d-6875-45b7-b07b-738b8f9545fc-image.png

     
    Here is the result:

    v2.gif

     

    Here is the project link:

    https://play.creaticode.com/projects/05790f959a134a91cea4adb1

     
     

    Example 2 - Both Objects are Dynamic

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

    In this project, we add a fixed box as well, and the 2 balls stay at the same distance even when they collide with the box.

    v3.gif

     
    Here is the project link:

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

     
     

    Remove the Rotation Axis

    To remove the rotation axis, you can use the following block:

    83d6473c-4ddb-44f0-9b74-cabd92435fee-image.png

     
     

    Set Rotation Speed for the Rotation Axis

    After setting a rotation axis, you can also set a rotation speed for that axis, which will make the current sprite rotate at that speed. This is handy if you want to simulate a wheel.

    You can use the following block to set the rotation speed:

    bbce4991-88bc-4b1a-83f2-c2765575b05f-image.png

     
    The speed input is a degree number. For example, if it is 180 degrees, the axis will rotate for 180 degrees every second.

    The second input is a damping factor between 0 and 100, which controls how fast the rotation speed slows down over time. At 0%, it will not slow down at all.

    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