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. Car with Physics Simulation

Car with Physics Simulation

Scheduled Pinned Locked Moved 3D Blocks
1 Posts 1 Posters 1.4k 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

    You can create a car with a physics body, which would allow you to drive and steer the car using its wheels. Many interesting games and animations can be created based on this.

     
     

    Pre-conditions

    Before you can create a car with physics simulation, your program has to prepare the following conditions:

    1. A 3D scene with physics enabled
    2. Some kind of ground with physics enabled to hold the car
    3. A car object, such as loaded from a car model

    The following is an example program for these steps:

    d8f2de17-85d3-4d9b-8742-caae5d2d2444-image.png

     
    Note that some car models do not support physics simulation because they do not model the wheels separately. You will need to test first when you choose a new car model.

     
     

    The “Enable Car Simulation” Block

    You can use the following block to convert a car object to a car with physics simulation:

    f04706fd-445d-41dd-833a-97d3d4720920-image.png

     
    It takes 4 input parameters:

    • Mass: This is the mass of the car body. The larger the mass, the stronger the engine force it takes to make the car move.
    • Restitution: This is how much the car rebounds when it hits an obstacle, such as a wall or another car.
    • Friction: This is the friction for the car’s body.
    • Tire Friction: This is not the friction of the car’s body itself. Instead, this is the friction between the tire and the ground. The higher the friction, the more “grip” the car has when it moves or turns. If the friction is low, then the tire will be slippery.
    • Name: This is the name of the car object. You can leave it blank if the car is the sprite object.

     
     

    Driving and Stopping the Car

    After you have created a car with physics simulation, you can use the following block to drive it or make it stop:

    157f768f-e3ee-499d-a2a2-6db0774dc4a0-image.png

     
    It takes 3 input parameters:

    • Engine Force: This is the force to be applied in the current forward direction of the car. If it is negative, then the car will drive backward.
    • Brake Level: This is a percentage value that controls how much brake to apply to the tires. When it is 0, no braking force is applied. When it is more than 0, the car’s moving speed will be reduced by this percentage each time this block runs. For example, if the brake level is 5, then the car’s speed will be reduced by 5% each time this block runs.
    • Name: This is the name of the car object. You can leave it blank if the car is the sprite object.

     
     

    Steering the Car

    You can turn the 2 front wheels of the car using this block:

    872e687a-7b93-43ef-aeda-8ff0dd1de236-image.png

     
    It takes 2 input parameters:

    • Angle: This is the angle for the front wheels. Normally it should be between -50 degrees and 50 degrees.
    • Name: This is the name of the car object. You can leave it blank if the car is the sprite object.

     
    Note that if the car’s front tires are not touching the ground, then steering the tires won’t change the car’s moving direction.

     
     

    Demo

    Here is a demo program that creates a physics-based car and handles these 5 keys:

    • W: drive the car forward
    • S: drive the car backward
    • D: steer the car right
    • A: steer the car left
    • SPACE: stop the car

    sss.png

     
    Here is what it looks like:

    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/ced08f73-5e99-4d63-bbd2-85e42b78d6ba.gif" width="480" style="border-radius: 5px; border: 1px solid #29622d;">

     
    Here is the shared project for you to try:

    https://play.creaticode.com/projects/9360a40de99763670d3bd3d4

     
     

    Issue with Shaking Wheels

    Sometimes you might find the wheels of the car are shaking rapidly, which also makes the car’s body shake. The most likely reason is that the ground is too big, which makes it hard for the physics engine to calculate the exact position of the wheels.

    shake.gif

     
    A simple solution is to make the ground object smaller, and you can use multiple planes to piece together the ground. For example, instead of having one plane that is 100000 by 100000, you can have 100 planes of 10000 by 10000 each, and arrange these planes in 10 rows and 10 columns.

    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