Distance in which Distance sensor runs a set of code

Im trying to find a way where the distance sensor decects something far and doesnt chase but if it is within (x distance) then it will run a line of code.

I’m still looking will update if I find a way

if (/*distance sensor distance*/ <= /*maximum distance*/) {
    // run code
}

What do you mean by “chase”?

1 Like

What I mean by chase is it drives toward the opponent.
Thanks for helping!

Since a distance sensor can only tell the distance from one object and can’t tell what that object is, it would be very hard to do this with just a distance sensor. It may be possible with a more advanced sensor, but it would still be very difficult to implement (mostly since it is hard to tell what is a robot), and it wouldn’t be that useful since you can’t cross the autonomous line during auton so there isn’t much benefit to being able to follow another robot. If you have managed to implement this though, that is very impressive since, as far as I know, no one has done this before.