About Speeds

Hello there,

Everything is working as intended so far :slight_smile: However, there are a few things that I would like to add to this.
I would like the speed boost to go away after some time has passed as I would not want the car to go fast indefinitely. The speed boost should also overwrite any slows during its active time. How can I achieve this?

I do not wish to slow the car at every collision as the level may at times be crowded with objects and constantly being slowed would be frustrating. Particularly because colliding with something is inevitable. Instead, I would like to make the movement speed slower on places that are not roads.

For this I created a Road tag and assigned it to the parent object that all roads were under. Then I did the following:

if(other.tag != “Road”)
{
moveSpeed = slowSpeed;
}

This caused the car to slow down when hitting something that is not a road. It also caused a slow down when hitting packages. How can I include multiple tags in this statement? How can I get the speed back to normal when the car gets back on the road? I assume there ought to be a good old else statement here somewhere that ends with moveSpeed = moveSpeed or something like that :slight_smile:

Thanks for your help :slight_smile:

Hi Ozberk,

I think coroutines might be a good solution for this problem. Look them up in the Unity manual. Alternatively, you could use the Invoke method.

You can add multiple conditions with && (and) or || (or).

The same way as you determine whether the car is not on the road. Just add an else if (your_condition) right below your if-statement. Or simply else if you just want to distinguish between “Road” and “not Road”. In the case of else, check for “Road” in the if-condition.

if (other.tag == “Road”)
{
    // your code
}
else
{
    // your code
}

I think you are on the right track, so I would suggest that you test your ideas yourself to figure out what works and what does not work. You’ll learn a lot by figuring out the solution yourself.

Let me know how it worked. :slight_smile:


See also:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms