- Home /
Child object not flipping with parent?
I have hands that point towards the mouse using this script:
public class HandController : MonoBehaviour
{
public void ReadMouseInput(InputAction.CallbackContext context)
{
Vector2 mousePosition = context.ReadValue<Vector2>();
Vector2 objectPosition = (Vector2)Camera.main.WorldToScreenPoint(transform.position);
Vector2 direction = (mousePosition - objectPosition).normalized;
RotateAim(direction);
}
public void ReadStickInput(InputAction.CallbackContext context)
{
Vector2 stickDirection = context.ReadValue<Vector2>().normalized;
RotateAim(stickDirection);
}
public void RotateAim(Vector2 direction)
{
float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.Euler(new Vector3(transform.position.x, transform.position.y, Mathf.Clamp(angle, -75, 75)));
}
}
And I flip the player using this code:
public void Flip()
{
if ((inputX < 0 && facingRight) || (inputX > 0 && !facingRight))
{
facingRight = !facingRight;
transform.Rotate(new Vector3(0, 180, 0));
}
}
the object with the rotation script is parented to the object with the flipping script. I want the gun to flip with the player so that it is facing the same way as the player at all times, but for some reason it is refusing to. Does anyone know of something I could add to either script as a way to work around this? thanks!
Answer by Hazsha · Dec 08, 2021 at 10:34 AM
Check you player initial Rotation is (0,0,0). if any change in parent rotation may cause child rotation
well, I want the child object to be flipping with my parent object, the problem is that it isn't
Your answer
![](https://koobas.hobune.stream/wayback/20220613050323im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Make a simple tree 1 Answer
Delay child objects rotation 0 Answers
How to flip my Bullet with my Sprite 1 Answer
Inheriting Parent Rotation and position 2 Answers
Parent-independent rotation 2 Answers