0 votes

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);
in Engine by (24 points)

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

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);
        }
    }

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.