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. Physics Engine for 2D Projects

Physics Engine for 2D Projects

Scheduled Pinned Locked Moved 2D Blocks
1 Posts 1 Posters 950 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 creating 2D projects, you can use a physics engine to help you handle object movements and collision. You can think of a physics engine as an AI assistant to you. You just need to describe what you need from it, such as “make this ball fall with gravity”, then it will take care of the actual work. Using a physics engine will not only make your program more concise, but also make the result look more realistic.

    Many great games are using a physics engine, such as “angry bird”, “pac-man”, or platformer games like “Super Mario”.

     
     

    Initialize the 2D Physics World

    To use the 2D physics engine, the very first step is to create a “physics world”. Unlike the stage or sprites, the physics world is an invisible world that works behind the scene. You will only know it is running by looking at the results it produces.

    To initialize this world, you can use the following block in the “2D Physics” category:

    a352ed26-2e89-4afd-a946-57733907bf25-image.png

     
    This block takes 2 inputs, which are the gravity values in the X and Y directions.

    • For a platformer game like angry bird where you want the objects to fall to the bottom of the screen, you should set X gravity to 0 and Y gravity to a negative value like -100.
    • For a top-down game like pac-man, you can set both gravity values to 0.

     
     

    4 Walls Around the Physics World

    After initializing the physics world, you will not observe any difference yet. However, 4 invisible walls will have been added on the 4 borders of the stage, so no object could move out of this area:

    39e7d4a8-fd33-4970-a87e-e8004753dc40-image.png

     
    Note that if you have set the canvas dimensions to be greater than 480 by 360 for the viewport mode, these walls will be added around the enlarged canvas area.

    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