Hello! I’m trying to run this python script to get an actor to run through specific coordinates based on a json file. I’m encountering a syntax error. Pls help me troubleshoot:
import json
import unreal
import pandas as pd
file_path = r"C:\Users\Nudgyt Data Science\coordinates.json"
with open(file_path, ‘r’) as file:
data = json.load(file)
def extract_coordinates(data):
coordinate_keys = [‘release_coord’, ‘bounce_coord’, ‘hit_coord’]
coordinates = {key: data.get(key) for key in coordinate_keys if key in data}
return coordinates
extracted_coordinates = extract_coordinates(data)
df_coordinates = pd.DataFrame.from_dict(extracted_coordinates, orient=‘index’).transpose()
def split_coordinates(row):
for coord_type in [‘release_coord’, ‘bounce_coord’, ‘hit_coord’]:
if pd.notnull(row[coord_type]):
row[f’{coord_type}_x’], row[f’{coord_type}_y’], row[f’{coord_type}_z’] = row[coord_type]
return row
df_coordinates = df_coordinates.apply(split_coordinates, axis=1)
df_coordinates.drop([‘release_coord’, ‘bounce_coord’, ‘hit_coord’], axis=1, inplace=True)
def move_sphere_actor(df, sphere_mesh):
for index, row in df.iterrows():
for coord_type in [‘release_coord’, ‘bounce_coord’, ‘hit_coord’]:
if f’{coord_type}_x’ in row:
x, y, z = row[f’{coord_type}_x’], row[f’{coord_type}_y’], row[f’{coord_type}_z’]
location = unreal.Vector(x, y, z)
rotation = unreal.Rotator(0, 0, 0)
sphere_actor = unreal.EditorLevelLibrary.spawn_actor_from_class(unreal.StaticMeshActor, location, rotation)
sphere_actor.StaticMeshComponent.set_static_mesh(sphere_mesh)
move_sphere_actor(df_coordinates, unreal.SM_Cricket_Ball)