Group Details Private

china users

paying users from China

  • RE: Clone Detections - help

    @011830-0a42ef84

    Currently there is no code to directly do this. You probably need to calculate their distances and find which one is “too close”

    posted in Help
  • RE: Position bugs near the edge on a larger box than normal

    @011830-0a42ef84

    The issue might be that the current code is highly “inefficient”. It is repeatedly erasing the bar and redrawing it, even if the health has not changed. Usually, you only need to redraw it when the health has changed.

    posted in Feedback
  • RE: Drawing a loading circle without sprites - help

    @011830-0a42ef84

    The draw oval block can only draw full circles, not partial ones.

    Why you can’t use sprites?

    If you can’t use sprites, can you use the Pen blocks to draw the circle segment by segment?

    posted in Help
  • Self-Driving Car AI - Following Driving Directions (Difficulty: 4)

    Introduction

     
    After the previous tutorial, our AI driver can automatically control the car to stay in lane, limit its speed, stop at the stop sign, and turn right at a crossing.

    In this tutorial, we will extend it further so that it can follow a list of driving directions to turn left/right or go straight.

    fsd4step8b

     
     

    Step 1 - Remix the Starting Project

     

    Please remix the following project:

    play.creaticode.com/projects/67ad8b0919667583370d2d81

     
    Note that the AI sprite contains the same logic from the previous tutorial, but the blocks have been divided into a few custom blocks to make them more readable:

    52fa37bb-5b5c-43ac-859d-fd8f89f8e8b3-image.png

     
     

    Step 2 - The “driving directions” list

     

    For a self-driving car in the real world, it will typically receive a destination from the passenger first, and it will calculate a driving direction based on that.

    We won’t get into how to calculate the driving direction in this tutorial. Instead, we will assume the directions have already been calculated, and we will represent them using a list named “driving directions”.

    Each item in this list will be a letter, which represents the direction at each crossroad:

    • L: turn left at the next crossroad;
    • R: turn right at the next crossroad;
    • S: go straight at the next crossroad;

    For example, suppose the driving directions list contains these 3 letters:

    4552f915-04cc-4f64-ba21-8f77622a4de1-image.png

     
    That means the car is expected to turn left at the next crossroad, go straight at the crossroad after that, turn right at the third crossroad, and then stop there.

     
     

    Step 3 - Read the next direction

     

    To keep our AI code simpler, we would only focus on the first direction from the list. After it is completed, we move on to the next direction on the list.

    We can use a new variable “next direction index”, which represents the index number of the next direction we have to follow. We will need to initialize this variable to 1 at the start:

    90de46b8-fb74-47d5-bda5-0e931a402e80-image.png

     
    We will use another new variable “next direction” to represent the actual direction. We will initialize it at the start as well, and we will update it after this direction has been fulfilled:

    32edc7f1-f708-45b5-9cfd-80018c043799-image.png

     
     

    Step 4 - Check for the lane on the left

     

    In the “normal” driving mode, we need to prepare for the next turn. For example, suppose the next direction is “L” for a left turn. If there are 2 lanes and our car is on the right lane, we need to switch to the left lane first, since we can not make a left turn from the right lane.

    To find out if there is another lane to our car’s left, we can use the “marker info” table, and look for the marker named “left marker”. If it exists, that means there is another lane to the left going in the same direction.

    Let’s define a new custom block named “update marker”, and run it at the beginning of the normal mode handler:

    9118325f-29fc-49b9-9140-3358e310720f-image.png

     
    In that block’s definition, whenever the next direction is “L”, we will get the index of the “left marker” from the “marker info” table:

    a71db503-64a1-4d3a-af9d-b8a9d93855e4-image.png

     
     

    Step 5 - Temporarily change the lane marker

     

    Suppose we have found another lane to our left, how do we ask the car to switch to that lane? The solution is very simple: we just need to aim at the lane marker from that lane, until the car enters that lane. After that, assuming there is no other lane on the left, our car will resume the old logic of following the lane marker in this new lane it has just entered.

    In code, we check if the index of the “left marker” is greater than 0, and if so, we would temporarily set the “marker angle” to be the angle relative to the marker in the left lane, not the current lane:

    33dce53b-8289-4486-b3aa-60d46d940e06-image.png

     
    That is all we need to make the car switch to the left lane. You can see that the “left marker index” is 2 when there is another lane on the left, and it changes to -1 right after the car enters the new lane. After that, the car reverts back to the normal mode of aligning to the lane marker in the lane.

    fsd4step5

     
     

    Step 6 - A new driving mode of “turnleft”

     

    To make the car turn left, we need a new mode of “turnleft”, similar to the “turnright” mode.

    Currently, when the AI is in “stopsign” mode, it always switch to the “turnright” mode after the car has fully stopped. We need to change that to determine which mode to use based on the next direction. The new “target dir” will also be different when the car needs to turn left: it will be the current direction of the car minus 90 degrees rather than plus 90 degrees.

    62d6532c-4651-4ed4-a2cf-52987ddeabe0-image.png

     
     

    Step 7 - Handle the “turnleft” mode

     

    We will define a new custom block to handle the logic of turning left at a crossroad, similar to the “handle turn right” block.

    cb83cb0c-3a69-4ceb-b262-e49078daa8a7-image.png

    d83fe299-dbee-4910-8b77-cdca701d098e-image.png

     
    To make the car turn left, we can reuse the same code for turning right, but change the engine force and steering angle. Can you give it a try?
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    [please try it yourself before looking at the next step…]

     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     

     
     

     
     

    Step 8 - The logic for turning left

     

    You should see that turning left involves a larger turn with a longer radius. There are many ways to set the engine force and the steering angle, and one example solution is the following, where the engine force is 10 and the steering angle is -9.5:

    40a80859-3f10-4329-b590-0d72fb780f2d-image.png

     
    This is what we will get now:

    fsd4step8b

     
     

    Step 9 - Move on to the next driving direction

     

    After the turn is completed, when we switch back to the “normal” mode, we should also update the “next direction” to the next item in the list:

    d46ec7d6-aa7b-4711-b304-a1ebddcada4d-image.png

     
    Note that this needs to be done in both the “handle turn left” and “handle turn right” blocks

     
     

    Additional Challenges

     

    At this point, our AI can drive the car to switch to the left lane and also follow the driving directions to turn left or right. There are a few missing pieces, so please use them as practice:

    1. Handle “go straight”: If the driving direction is “S”, the car should go straight across the crossroad. Please add logic to handle this case. For a hint, you can use the car’s distance from the starting point of the lane ahead (the “forwardxy” column of the lane marker) as a threshold: if the car is close enough to this point, you can switch back to normal mode.

    2. Switch to the right lane: when the next direction is “R”, and our car is still on the left lane out of 2 lanes, it should switch to the right lane.

    3. Stop at the end: when all the driving directions on the list have been fulfilled, the “next direction” becomes empty, then the car should switch to the right lane if it is not in that lane and then stop.

    You can test your AI with a list of directions like this: L, S, R, R, S, R, R, S

    posted in Tutorials
  • RE: feature request: DeepSeek AI blocks

    @jeffreyrb03-gmail

    We reviewed DeepSeek, but it does not meet our safety requirements yet. It has only implemented a minimal safety guardrail, so we can’t support it in our platform at the current stage.

    posted in Feedback
  • Self-Driving Car AI - Making Right Turns (Difficulty: 4)

    Introduction

     
    In the previous tutorial, we created an AI driver that can steer the car toward the center of the lane with the help of a lane marker.

    In this tutorial, we will make the car stop at the stop sign at the end of the current street and then make a right turn.

    fsd3step7

     
     

    Step 1 - Remix the Starting Project

     

    Please open the following project and remix it into your own:

    play.creaticode.com/projects/67abea71019e21d07d95ed17

     
    In this project, the AI sprite already contains the logic from the previous tutorial:

    cd0ed377-5bf7-41c1-9697-d4afa190590e-image.png

     
    When you click “Start”, the car will go back into the center of its lane, and stop after 5 seconds. We will use this code as our starting point.

     
     

    Step 2 - Read information about the stop sign

     

    The stop sign is a very important object. It not only tells us where is the end of the current street, but also requires our car to make a full stop. However, we should not deal with stop signs unless we are close to one, otherwise it will be a waste of time to constantly review all stop signs on the map.

    For this purpose, our simulation environment provides the following information to the AI driver:

    1. When the lane marker arrives at the stop sign, it will stop moving forward, and also turn red.
    2. In the “marker info” table, the column “stop” will become 1 when the lane marker stops at the stop sign.
    3. In the “marker info” table, these 3 columns will tell us the starting point of the next lane if the car needs to turn left/right or continue forward.

     
    Now let’s observe these information by running the program. When you click the “Start” button, you will see the the lane marker will stop moving at the stop sign and turn red:

    fsd3step2

     
    At this point, turn on the monitor of the “marker info” table, and you will see these columns on the right:

    • stop: this column is 1 when the lane marker is stopped at a stop sign, and empty otherwise;
    • leftxy: this is the x and y positions of the starting point of the next lane if the car needs to turn left. It is empty when there is no way to turn left or when that information is not provided.
    • forwardxy: this is the x and y positions of the starting point of the next lane if the car needs to continue forward. It is empty when there is no way to continue in the same direction or when that information is not provided.
    • rightxy: this is the x and y positions of the starting point of the next lane if the car needs to turn right. It is empty when there is no way to turn right or when that information is not provided.

    6b5e92fa-e55c-4c22-b284-f9dc5d93ad0e-image.png

     
    As you can see, “stop” is 1, indicating the lane marker is at a stop sign. Also, the “rightxy” column is “260_2427”, which means for the car to turn right, the next lane will start at the position of (260, 2427).

    We can add 2 new variables that are related to the stop sign:

    • is stop: whether the lane marker is stopped at a stop sign;
    • distance: distance to the lane marker;

     
    1698fbc2-8009-47a6-b9a7-67650b79609c-image.png

     
    Next, we will use this information to control the car.

     
     

    Step 3 - The Driving Mode

     

    To make our car stop at the stop sign, our AI will give different commands to the car than to make the car go forward. To clearly indicate what our AI driver is doing, we will use a new variable “driving mode”, which will have these values:

    • It will have a value of “normal” when the car is going forward
    • It will have a value of “stopsign” when we need to stop the car for a stop sign.

    When the AI driver starts, it will be in the “normal” mode:

    c4d986bd-77fa-426c-9234-c9e037743451-image.png

     
    And we will use 2 “if” statements to organize our logic based on the driving mode:

    • If the driving mode is “stop sign”, we set the brake level to stop the car
    • If the driving mode is “normal,” we apply our existing logic of keeping the car in the lane center and under the 100 speed limit.

     

    blocks (44).png

     
     

    Step 4 - Switch to the “stopsign” driving mode

     

    We are still missing an important logic: how do we switch from the “normal” mode to the “stopsign” mode?

    While we are driving the car normally, we need to keep an eye on the stop sign information. If the lane marker has stopped at a stop sign, and if our car is very close to the lane marker (distance < 80), then it is time to switch to the “stopsign” mode. In code, this logic is the following:

    9bb5a40f-8c76-4d80-b3f7-898db871b903-image.png

     
    Now our logic for stopping is complete. We no longer depend on the timer value, and the car automatically stops before the stop sign.

    fsd3step4

     
     

    Step 5 - Switch to the “turnright” driving mode

     

    After the car has stopped, we need to make the car turn right. We can introduce a new driving mode of “turnright”, so that we can put all the code for turning the car right in that mode.

    We need to carefully consider when to switch to the “turnright” mode. There are 2 issues we need to handle:

    • When the AI set the brake level to 100, the car may not immediately stop. Depending on its speed, it might take some time to come to a full stop.
    • Even after the car has fully stopped, we should not start the right turn right away. It is better to wait some time.

    To handle these issues, we can use the following logic to switch from the “stopsign” mode to the “turnright” mode. Basically, we will wait until the car’s speed is almost 0 (less than 1), and then wait another 1 second, and then switch to the “turnright” mode.

    1339b174-2ab6-44af-8ea1-9ab1f7a8f960-image.png

     

     
     

    Step 6 - Make the car turn right

     

    Now we can start to add logic to control the car in the “turnright” mode. To start simple, we can simply set a small engine force and steer the car to the right by 25 degrees:

    99f85474-b7a3-4cf6-99ba-8d06d6f7121b-image.png

     
    Now let’s observe what happens:

    fsd3step6

     
    Our AI has successfully made the car turn right. Next, we will need to think about when to exit the “turnright” mode so the car can drive normally on the new street.

     
     

    Step 7 - “car dir” and “target dir”

     

    One simple way to determine if the car has fully turned right is to check if its direction is aligned with the new street’s direction.

    First, let’s add the “car dir” variable, which will store the direction of the car (read from the “car info” table):

    3693e54d-3323-475f-a6fd-a06923731b7e-image.png

     
    Next, when we switch to the “turnright” mode, we can use another variable “target dir” to store the desired driving direction of the car, which is the current direction of the car plus 90 degrees (since we are turning right by 90 degrees):

    1b087c95-bebc-4d0e-9c11-48804b5f6a8c-image.png

     
     

    Step 8 - Compare “car dir” and “target dir”

     

    The last step is to keep checking if the car’s direction is aligned with the target direction, and when that happens, switch back to the “normal” driving mode.

    To do that, we can first calculate the absolute difference between the car’s direction and the target direction. The “abs” operator ensures we only look at their difference, and it does not matter which value is greater.

    132ad763-c768-4401-b1e3-7179a0cd34b2-image.png

     
    Next, if the direction difference is very small, then we can switch back to the “normal” mode:

    fd10bfc7-ee45-4088-b2d2-40dff10d10e0-image.png

     
    Note that we also check if the direction difference is greater than 355. This is because the direction value is always between -180 and 180 degrees, so if 2 directions are 179 degrees and -178 degrees, their difference is 357 degrees, but they are actually only 3 degrees apart.

    In summary, here is the full logic for handling the “turnright” driving mode:

    6b0cedff-3b30-4ead-94e9-7e8c2d90acf6-image.png

     
    Now our car will keep driving happily in a large square:

    fsd3step7

     
     

    Additional Challenges

     

    Here are some challenges for you to improve our AI driver further:

    1. Currently the car will cut into the corner of the curb. Can you improve the “turnright” mode further so the car makes a clean right turn?
    2. Can you try to make the car turn into the left lane in the new road? It is the lane with the yellow line on its left, which requires a bigger turn for the car.
    posted in Tutorials
  • RE: Creating leaderboards with saved variables

    @011830-0a42ef84

    You can click this green button on the bottom left to add the “Game” extension:

    fc55cf9a-148c-4cab-ac0d-137acadbd936-image.png

    posted in Help
  • RE: Creating leaderboards with saved variables

    @011830-0a42ef84

    It is in the “Game” extension.

    posted in Help