Endless Runner Problem

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

I’m making a little endless runner. My city has three parts. When you collide with the end of the first part (placed in between the other two), part 3 (again, behind part 1) moves three slots ahead. Collide with 2 and 1 moves 3 parts, and so on. The problem is that in the editor each part is 3042 units long. Moving the city chunks by 9126 units makes them disappear altogether. I’ve also tried programmatically getting the chunks’ sizes by using the code below, but the printout gives me size (0, 0, 0) no matter where I instance the boundingBox. Help?

AABB boundingBox = city.GetTransformedAabb();
Vector3 size = boundingBox.Size;
GD.Print("City size: "+size);

How do you move them? Care to show the code?

Skipperro | 2019-08-01 10:52

This is the collision-detection and subsequent translation of the city chunks.

    public override void _PhysicsProcess(float deltaTime) {
		Transform transform = base.GetTransform();
		Vector3 dir;
		if (!flying)
			dir = new Vector3(transform.basis.z.x*(float)deltaTime*100f, transform.basis.z.y*(float)deltaTime*100f, transform.basis.z.z*(float)deltaTime*100f);
		else dir = new Vector3(transform.basis.y.x*(float)deltaTime*300f*currentSpeed, transform.basis.y.y*(float)deltaTime*300f*currentSpeed+(up*deltaTime), transform.basis.y.z*(float)deltaTime*300f*currentSpeed);
		KinematicCollision collision = MoveAndCollide(dir);
		if (collision == null)
			return;
		Transform globalT = GetGlobalTransform();
//		Vector3 xTranslation = new Vector3(globalT.basis.x*new Vector3(-9126f, 0f, 0f));
//		GD.Print("Translation: "+xTranslation);
		Vector3 xTranslation = new Vector3(-9126f, 0f, 0f);
		StaticBody collider = collision.GetCollider() as StaticBody;
		if (collider.GetName().Equals("Chunk1StaticBody") && (int.Parse(OS.GetTime()["minute"].ToString()) > lastColMinute || int.Parse(OS.GetTime()["second"].ToString()) > lastColSecond+2)) {
			chunk3.Translate(xTranslation);
			string minute = OS.GetTime()["minute"].ToString(), second = OS.GetTime()["second"].ToString();
			lastColMinute = int.Parse(minute);
			lastColSecond = int.Parse(second);
			(collider.GetNode("CollisionShape") as CollisionShape).Disabled = true;
			GD.Print("Moved chunk 3. Time: "+lastColMinute +": "+lastColSecond);
		}
		else if (collider.GetName().Equals("Chunk2StaticBody")) {
			city.Translate(xTranslation);
			(collider.GetNode("CollisionShape") as CollisionShape).Disabled = true;
		}
		else if (collider.GetName().Equals("Chunk3StaticBody")) {
			(collider.GetNode("CollisionShape") as CollisionShape).Disabled = true;
			chunk2.Translate(xTranslation);
		}
	}

OriginalAGP | 2019-08-01 18:42