1

I implemented this simple code to test the spectator in Carla. However the spectator view is not aligned with the vehicle view. The car is looking forward while the spectator is looking backward.

import carla
import math
import time
client = carla.Client('localhost', 2000)
client.set_timeout(10.0)
world = client.get_world()
blueprint_library = world.get_blueprint_library()
vehicle_bp = blueprint_library.filter('vehicle')[0]
spawn_point = world.get_map().get_spawn_points()[0]
vehicle = world.spawn_actor(vehicle_bp, spawn_point)
car_transform = vehicle.get_transform()
spectator = world.get_spectator()
while(True):
 spectator.set_transform(car_transform)

I am using carla 0.9.16

Progman
20.1k7 gold badges60 silver badges89 bronze badges
asked Sep 20, 2025 at 10:33

1 Answer 1

0

I finally figured out the issue.
In Carla, usually the cars drop from the sky and then they stabilize after hitting the ground to get their initial pose. I just needed to keep getting the car transform in the while loop to correct for the mismatch between the car pose at the start of simulation (when i call the spawn_actor function) and the initial car pose after hitting the ground. The corrected code is given below:

import carla
import math
import time
client = carla.Client('localhost', 2000)
client.set_timeout(10.0)
world = client.get_world()
blueprint_library = world.get_blueprint_library()
vehicle_bp = blueprint_library.filter('vehicle')[0]
spawn_point = world.get_map().get_spawn_points()[0]
vehicle = world.spawn_actor(vehicle_bp, spawn_point)
spectator = world.get_spectator()
while(True):
 car_transform = vehicle.get_transform()
 spectator.set_transform(car_transform)
answered Sep 23, 2025 at 10:41
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.