Hello, I’ve been struggling with a problem recently. I’m making a game that is mainly about jumping from one rotating circular object to the other. The problem is the rotation. I want the player to fly to the other object and then invert himself so that it will look like he’s standing on that object. The player automatically gets parented by the “planet” so i was trying to use Transform.localRotation like so: private void OnTriggerEnter2D(Collider2D collision) { if (collision.tag == "Platforms") { transform.SetParent(collision.transform); //setting the parent transform.localRotation = Quaternion.identity; //trying to nullify the rotation, based on the parents rotation }
A snippet of code, where the rotation and parenting happens. When the player is moved again, the player object unparents itself.
The result:
The rotation seems to be random, so it must be based on the parent’s rotation. The player has a rigidbody attached to it. Thank you for any and all feedback :).
I’m gonna guess and say that this is because the circles in the picture you gave have a rotation value. Being circles, you can’t really see it, but they have one none the less. So the circle is rotated some angle, let’s say 45 degrees. When you set to localRotation to Quaternion.identity, that has the same effect as giving the player the rotation of the parent - in this case the 45 degrees.
What you could do is get the vector from the center of the circle to the player and then align your characters up vector with it:
Vector3 circleNormal = transform.position - circle.transform.position;
Quaternion rot = Quaternion.FromToRotation(Vector3.up, circleNormal);
transform.rotation = rot;
No errors, but the player is now further from the circle and when he moves to another circle, the distance between the player and the circle instantly becomes enormous (it seems that the further the platform is from the first circle, the bigger the gap is), like so: Screenshot by Lightshot ( this is quite a bit away from the start, the gap is so huge, the player is out of bounds completely). This could mean, that some of the variables do not reset… here is the full script, maybe you could see where.
@jdean300