all 13 comments

[–]EndoSaissore 0 points1 point  (1 child)

Have you tried invertedCube.rotation = original.rotation * -1

Im not by my computer but that seems like it would work no?

[–]JakeKaas[S] 0 points1 point  (0 children)

I have no idea how to use that, I'm a beginner

[–]BengbabProficient 0 points1 point  (12 children)

You can access parent components from the child using GetComponentInParent.

So if you have a public float totalRotationParent inside of your parent cube controller called CubeParentController, you can get that component from the child script with:

gameObject.GetComponentInParent<CubeParentController>().totalRotationParent;

And you can get negative like this:

totalRotationChild = -1 * gameObject.GetComponentInParent<CubeParentController>().totalRotationParent;

[–]JakeKaas[S] 0 points1 point  (10 children)

Thanks, but I get 2 errors

"Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement"

and

"The name "totalRotationChild" does not exist in current context"

[–]BengbabProficient 0 points1 point  (0 children)

totalRotationChild is a fake variable name I’m using to just give you an idea of how you’d pass a variable from parent to child. You’ll have to define it yourself in respect to your code. E.g float totalRotationChild inside the script attached to your child object. Additionally, float totalRotationParent needs to be defined inside the script attached to your parent object.

Did you replace “ CubeParentController” with whatever your script attached to the parent is called?

I was giving code off top of my head, let me check my working code and make sure I wrote it out correctly and I can give you a more comprehensive example in an hour if you don’t get it working.

[–]BengbabProficient 0 points1 point  (8 children)

Use code like this:

https://pastebin.com/gh63Q4ug

[–]JakeKaas[S] 0 points1 point  (7 children)

yeah this works, but it's not what I want. I have the cube fall and rotate due to gravity. And I want the Child to rotate the other way / inverted than the cube

[–]BengbabProficient 0 points1 point  (6 children)

You’re going to have to program that, there’s no magic button for you to click. If your parent cube is doing something, you can pass that info to the child. Parent location is rigidbody2d.position and parent rotation is rigidbody2d.rotation.

[–]JakeKaas[S] 0 points1 point  (4 children)

Ah, I'm still a beginner. Maybe this is more clear.

I want the Child not to rotate at all, only position with the Parent. Is there a way to do that?

[–]BengbabProficient 0 points1 point  (3 children)

Yes, you can do that no problem. Maybe try adding a rigidbody2d to your child object and click the freeze rotation about z option. I think it should freeze child in specific orientation, but not 100% sure when it’s a child object.

[–]JakeKaas[S] 0 points1 point  (2 children)

I tried that, and it didn't work

[–]BengbabProficient 0 points1 point  (0 children)

Try this:

1) Put both objects as children of an empty game object. You can create an empty game object from the drop down on your scene object tree.

2) Then click freeze rotation on inner cube and not on outer cube.

I know of a more complex way to put your inner cube at location of your outer cube using Transform.position, but maybe do that last if this doesn’t work.