How can I make a pedestrian walk towards the vehicle?

I wrote the below code to spawn a pedestrian and walk towards the vehicle. Below code is spawning the pedestrian at the correct position I desired but is not walking. I know the spawn position of the vehicle which I have used as go to location hence expecting pedestrian to walk towards the vehicle. Can some one help with what I am missing ?

import glob
import os
import sys
import time
import carla
from carla import VehicleLightState as vls
import argparse
import logging
from numpy import random

#step 1- connect to server
client = carla.Client(‘’,2000);

#step 2- get the world; get list of pedestrians from blueprint lib and choose one
world = client.get_world()
blueprintsWalkers = world.get_blueprint_library().filter(“walker.pedestrian.*”)
walker_bp = random.choice(blueprintsWalkers)

#step 3- get a list of random points where to spawn the pedestrians - these points are away from the areas where the pedestrian can walk:

spawn_points = []
for i in range(1):
spawn_point = carla.Transform()
spawn_point.location = world.get_random_location_from_navigation()
spawn_point2 = world.get_map().get_spawn_points()[10]
spawn_point.location = spawn_point2.location

#step 4 - build the batch of commands to spawn the pedestrians at the above positions
batch = []
for spawn_point in spawn_points:
walker_bp = random.choice(blueprintsWalkers)
batch.append(carla.command.SpawnActor(walker_bp, spawn_point))

apply the batch

results = client.apply_batch_sync(batch, True)
walkers_list = []
for i in range(len(results)):
if results[i].error:
walkers_list.append({“id”: results[i].actor_id})

#step 5 - we spawn the walker controller
batch = []
walker_controller_bp = world.get_blueprint_library().find(‘’)
for i in range(len(walkers_list)):
batch.append(carla.command.SpawnActor(walker_controller_bp, carla.Transform(), walkers_list[i][“id”]))

apply the batch

results = client.apply_batch_sync(batch, True)
for i in range(len(results)):
if results[i].error:
walkers_list[i][“con”] = results[i].actor_id

#step 6 - we put altogether the walkers and controllers id to get the objects from their id
all_id = []
for i in range(len(walkers_list)):
all_actors = world.get_actors(all_id)

wait for a tick to ensure client receives the last transform of the walkers we have just created


#step 7 - initialize each controller and set target to walk to (list is [controller, actor, controller, actor …])
for i in range(0, len(all_actors), 2):
# start walker
spawn_point3 = carla.Transform()
spawn_point3.location = world.get_random_location_from_navigation()
spawn_point4 = world.get_map().get_spawn_points()[12]
spawn_point3.location = spawn_point4.location
# set walk to random point
# random max speed
all_actors[i].set_max_speed(1 + random.random()) # max speed between 1 and 2 (default is 1.4 m/s)

1 Like

Im having the same problem…


I tried “world.tick()” at the end of the code and that works for me. (in my code, but it is quite similar to yours)

Thanks for the comment - Pedestrian is now walking!!

However I spawned the Pedestrian at the middle of the road and wanted it to walk towards the vehicle. The Pedestrian is spawned initially at the middle of the road but when it starts to walk it is suddenly spawned to the left side of the road and the pedestrian is walking towards the sidewalk. Is the areas that Pedestrian can walk restricted ? If so, how can we get it to walk towards the vehicle from middle of the road? How can the restrictions be modified ?

Hi, welcome :slight_smile:

I’m haing the same problem with the pedestrians.

After a little bit of research I find out that after a CARLA update, pedestrians can only walk in permitted regions (like sidewalk). Take a look at this discussion, it might help you: