Help with code translation

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By StrikerSVX

Hello, Striker here, in the past i attempted to make a racing game on Unity, the project was good but i didn’t like the way things were going there, i need some help to make the transition of a very important code from Unity to Godot this is the code:

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class PathRace : MonoBehaviour
	public Color limeColor;
	private List<Transform> nodes = new List<Transform>();
	private void OnDrawGizmos()
        Gizmos.color = limeColor;
		Transform[] pathTransforms = GetComponentsInChildren<Transform>();
		nodes = new List<Transform>();
		for(int i = 0; i < pathTransforms.Length; i++)
			if(pathTransforms[i] != transform)
		int count = nodes.Count;
		for (int i = 0; i < count; i++) 
            Vector3 currentNode = nodes[i].position;
            Vector3 previousNode = nodes[(count-1+i) % count].position;
            Gizmos.DrawLine(previousNode, currentNode);
		Gizmos.DrawWireSphere(currentNode, 2.5f);

What this code do is to draw on the editor a “path” between various “nodes” creating a circuit of nodes where later i can tell my racer ai to drive through this circuit, the code is very simple in Unity but i don’t really know how to achieve the same on Godot, or at least something near that, any type help or direction i could go would be appreciated!

:bust_in_silhouette: Reply From: rahsut

To be completely honest, it would probably be better to rewrite the code completely. The reason I say this is because the problems that could occur from just making transition would probably take more time than to rewrite it. I could be completely wrong, that’s up to you but I recommend just rewriting the code. Also, another reason is that stuff that you can do in the Unity engine might not exist in the Godot engine. Transitioning that would be difficult.

Hope this helped. This may not be what you wanted to hear but I hope this still gave you some feedback though!

Thanks, i already tried and i got mostly of the code i needed to work, except the part that this code have the purpose to draw on the editor, i tried everything but it seems that there’s no simple way to do it.

StrikerSVX | 2020-07-23 16:25

I’m happy I was able to help :slight_smile:

About the second part, I’ve only made 2D games so I’m not completely sure on how to help you on that one (sorry for late response).

rahsut | 2020-08-17 13:58