The third condition does the same as the second, but to the right. This moves the car 10 pixels to the left, along the horizontal.
That’s what the blue line of code is for – change x by -10. At the same time, you want the car to move sideways so it can change lanes. When the condition is met, costume 2 will show, where the car is facing diagonally left.
(Vertical = less than 20 degrees, Left = more than 20 degrees.) If you change the vertical range in Condition 1, make sure you update Conditions 2 and 3 to match. The degrees selected should be the same as the condition for vertical, so that there’s no overlap or gap in the code. The second condition applies when the tilt sensor is more than 20 degrees to the left. We found that 20 degrees either side was good, but you may prefer something different. If the range is too small, you’ll find it hard to hold the steering wheel close enough to vertical, and the racing car will veer off to the side when you don’t want it to. Very important for this part of the code is to nominate a suitable range either side of vertical. Under those conditions, costume 1 will show, which is when the car is facing straight ahead. The first part of this code applies when the tilt sensor is close to vertical – less than 20 degrees either left or right. All three are inside a forever loop, so the sprite will constantly check which condition is applicable. That’s one condition for each costume, so that the sprite knows what to do. Notice that there are three ‘if’ conditions in this section of code. At the same time, we want the car to move left or right when we turn the steering wheel, so the blue lines of code tell the car to move along the horizontal axis.įinal part of the code for the racing car, using Lego Wedo tilt sensor blocks
It’s controlled by the tilt angle of the sensor, either left, right, or vertical. The first is to control which costume is used for the racing car sprite. In this code, the tilt sensor is used to instruct two different actions simultaneously.
How to connect Lego Wedo 2.0 to Scratch.We’re using the left/right detection in the code for the racing car game. For the racing car project, the sensor is fixed vertically to the central bar of the steering wheel. The sensor can detect up/down and left/right movement, which it feeds to the smarthub. The steering wheel was the first project that required the sensor, so there was a lot of learning. Liam has been working on some other Wedo projects recently, but they’ve been using only the motor and the smarthub. The tilt sensor is one of the key components in the Lego Wedo 2.0 kit, along with a motion sensor, motor and smarthub. Lego Wedo tilt sensor attached to the back of the steering wheel It’s taken a while, but it’s definitely worth getting the rest of the code up and running. In the final section of code, the Lego Wedo tilt sensor finally comes into the game. The game only supports two players, and all you and a pal can do is race each other on tracks you've opened.Racing car code part 3 – when the car crashes Part 4 – using the tilt sensor on the steering wheel But it's the lack of multiplayer options that really hurts Lego Racers' replay value. In fact, you'll spend most races tracking down just turbos and ignoring other weapons. The turbo is really the only power-up that matters, since it becomes a teleporter that warps you miles ahead once you fully charge it.
You can also supercharge each weapon by picking up white Lego pieces. And the power-ups are the usual kinda thing-turbos, guided missiles, oil slicks, etc. Some track obstacles can be downright frustrating (such as flying saucers that zap you backward). The colorful courses pack the expected allotment of shortcuts. There's no limit to vehicle variety, either build your own cars using pieces from classic Lego kits (new kits open when you win each circuit). Instead of having to hop to pull off a power slide, you just press the power-slide button (Ri), or press both it and the brake button for a super-duper slide. Lego Racers is simple, pure racing fun, with 25 well-designed tracks and tight control. It certainly won't take you long to figure this game out. Bored of Mario Kart 64? Fed up with Diddy Kong Racing? You could do a lot worse than pick up Lego Racers.