Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

How to make child rigidbody rotate independently, as though rolling along ground?

Discussion in 'Scripting' started by HopelessHyena, Aug 18, 2015.

  1. HopelessHyena

    HopelessHyena

    Joined:
    May 26, 2015
    Posts:
    18
    Hello everyone,

    I am trying to replicate a football rolling along the ground when a player is dribbling it. The football has a rigid body and collider, and the player uses a nav mesh to move about.

    At the moment, when a player gets close to the football, the football is parented to the player with an offset of a small distance. At this instant, I remove all velocity from the football to prevent it from rolling away if it is already in motion. This all works as I expect it to.

    However, where the football does move relative to the player, it doesn't rotate relative to the ground. I want to make the football rotate somehow to give the appearance of it rolling along the floor- I am perfectly happy for it to simply rotate by a constant amount every second.

    I've tried adding torque to the ball, incrementing it's x-axis rotation every frame, giving it force, but none of these have worked; the ball remains static in its rotation.

    What can I do to make it rotate, please?
     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    separate the model from the physics by having the mesh components on a child of the gameobject with the rigidbody, then just rotate the model child? visual rotation, but no actual physics interactions.
     
  3. HopelessHyena

    HopelessHyena

    Joined:
    May 26, 2015
    Posts:
    18
    I've tried doing exactly that but it hasn't worked - exactly the same problem persists.
     
  4. HopelessHyena

    HopelessHyena

    Joined:
    May 26, 2015
    Posts:
    18
    Oh, I have managed to make it work - although I'd tried it before, I used your suggestion again and realised my code for constantly rotating the ball was wrong (of all things...)! Thanks for your help!