0
\$\begingroup\$

My current code is:

if (tag == "RockWeak")
        {
            transform.position = new Vector3(1.0f, 1.0f, 1.0f);
            hits = hits + 1;
            print(hits);
            bigLava = GameObject.Find("BigLava");
            bigLava.transform.position += Vector3.up * 1f;

        }

The parent object in question is a red box named "BigLava", and the child object is a white box named "RockWeak". Both of them have 2D box colliders and RigidBody 2D. The idea is that the player (robot boy) should be able to jump on top of the white box (RockWeak) without being killed by the red box (BigLava), and then both RockWeak and BigLava move upwards.

The scene in scene view, before it's loaded. The white box overlaps the red box.

This is the level in scene view. That white box on top of the red box is the "rock weakness". (it looks very simple and I know that, it's just for testing and learning basics)

This is the box after the player has hit RockWeak, the white box is no longer overlapping the red box and is above it.

This is what happens when robot boy hits the white box (RockWeak) which is childed to the red box (BigLava). The code earlier (DetectCollision) is connected to Robot Boy. I have zero idea how to fix this.

\$\endgroup\$
1
  • \$\begingroup\$ It is easier to just move the parent instead of moving both the child and afterwards the parent (since that moves the child twice) \$\endgroup\$
    – Zibelas
    Commented Apr 2 at 12:22

1 Answer 1

0
\$\begingroup\$

Fixed! Turns out my y constraint wasn't frozen on the rigidbody.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .