How to randomly position a vehicle across three predefined waypoints?

I want to randomly position a car across three distinct locations: a garage, a road, and a rail.

To implement this, I created a state variable called carState and assigned it a random integer value between 0 and 2. Where 0 is a garage, 1 is a road, and 2 is a rail.

Then, I used conditional statements (if / else if) so that if the value is 0, the car moves to the garage; if it’s 1, it moves to the road; and if it’s 2, it moves to the rail.

How should I properly program this logic with CoBlocks? https://edu.delightex.com/QVH-NAN

Hello!

This issue here is you have set “Random Number” - which looks like a float (any value between 0 and 2, including decimals).

You need to use "Random Integer” which will keep the numbers as whole numbers.

Cheers

1 Like

It works perfectly. Thanks!

2 Likes