Search Unity

Question Rigidbody2D component does not work as intended (Beginner)

Discussion in 'Physics' started by IronWolf03, Feb 21, 2021.

  1. IronWolf03

    IronWolf03

    Joined:
    Feb 21, 2021
    Posts:
    1
    Hello people!

    Right now I'm working on a 2D game. In the game I have a player (parent) and a gun (child) which is supposed to rotate 360° around the player.
    Both the player and the gun are controlled by a Rigidbody2D script.

    Now the problem:

    When i move the player im not able to move the gun, only when the Rigidbody component on the player(parent) is sleeping, the gun(child) rotation script (made with Rigidbody2D) is able to run.

    Here's a video: Rigidbody madness - YouTube

    It seems like the to Rigidbody2D components connot run at the same time.
    What can i do to fix this and if not, what can i do alternatively?

    Infos:

    - player(parent) is a sprite with cirlcle colider 2D and rigidbody2D movement script + the rigidbody2D rotation script for the gun(child). This script for the gun references the rigidbody2D on the gun.
    - gun(child) is a empty with rigidbody2D

    I hope youre are able to help me with this problem.
    Thank you in advance.
     
  2. Newermind

    Newermind

    Joined:
    Aug 10, 2019
    Posts:
    4
    Can you show us that part of code which handle rotating of gun? Why you have Rigidbody on gun GameObject?