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
  4. Dismiss Notice

Making Hinge Joint with motor not push and stop itself when it hits something

Discussion in 'Physics' started by Power37371, May 23, 2022.

  1. Power37371

    Power37371

    Joined:
    Sep 22, 2019
    Posts:
    7
    I have a non-kinematic rigid body (we will call this the vehicle), I have a non-kinematic rigid body attached using a hinge joint to that non-kinematic rigid body (we will call this the motor). The motor colliders should not collide with the vehicle colliders, and instead I want to attach a kinematic rigidbody (this will just be a copy of all the colliders of the vehicle rigidbodys' colliders) to the vehicle such that in anyway the non-kinematic rigid body moves, the kinematic rigid body moves rotates etc to the exact same place, and that movement should happen during the internal physics update (moving it in the fixed update wont work.) I have tried attaching the kinematic rigid body using a fixed joint, that stops the vehicle from being able to move at all (it seems that kinematic body takes precident or smth), I have tried parenting the kinematic body to the non kinematic body, but then when the motor hits the kinematic rigidbody it just phases through and also it ends up adding forces to the vehicle (as if it was non-kinematic... very weird). The end result i want is that when the motor hits the vehicle it is attached to, it will just stop moving in that direction, but it will add no force to that vehicle, so vehicles cant catapult themselves, but if the motor hits the ground or another vehicle, it can still add forces to them etc.

    Any help will be greatly appreciated. :)
     
    Last edited: May 23, 2022
  2. arfish

    arfish

    Joined:
    Jan 28, 2017
    Posts:
    777
    Hello,

    I think you should try to make it as easy as possible. Dont parent rigidbodies to other rigidbody gameobjects. The physics system is not meant for it. Instead, when a player for example is entering a vehicle, destroy one of the rigidbodies, and re route the listeners for collisions, and triggers to be catched from the active rigidbody instead. If you want different behavior for the vehicle depending on the weight of the load, or number of peoples in it, just change the rigidbody mass.
     
    Last edited: May 24, 2022
  3. Power37371

    Power37371

    Joined:
    Sep 22, 2019
    Posts:
    7
    Im using hinges and as far as im aware I need multiple rigidbodies when using hinges (Specifically the hinge joint.) If the colliders attached to the hinge joint hit the vehicle I need it not to move the vehicle, and as far as im aware the easiest way of doing that would be using a kinematic rigidbody, as much as multiple rigidbodies doesnt seem ideal it seems like the easiest or maybe only way of doing what im trying to achieve unfortunately.
     
  4. tjmaul

    tjmaul

    Joined:
    Aug 29, 2018
    Posts:
    464
  5. Power37371

    Power37371

    Joined:
    Sep 22, 2019
    Posts:
    7
    Ive being trying contact modifications, I first tried setting the mass of the object getting hit much higher or a little bit higher than the pole hitting it, but that seems to result in undesired results. I've found that setting the contacts to have a bounciness of 0.0 helps for not making the pole excert any force on the thing it hits, but it did seem like the velocity of the pole wasnt going down at all once it hit, so ive tried implementing some sort of system to try to slow down the pole after a hit, based on the angular velocity and hit direction. This does seem to slow down the Y angular velocity but then as the pole rubs against the block the x and z components of the angular velocity goes up as the pole tries to twist in another direction against the block, ive tried countering this by making it so the angular velocity vector cannot be twisted be a value that goes against the axis of the hinge, which does seem to in some cases make the pole rub against the block for longer before it goes through, but doesnt fix the problem entirely.
     
  6. Power37371

    Power37371

    Joined:
    Sep 22, 2019
    Posts:
    7
    I had something on before that made it so my hinge force had to be infinite for it to move, thats not the case anymore and so I can set the force on the hinge motor to something nice and low, but unfortunately i have no clue what I changed so that it doesnt have to be infinite, anyway now it works pretty much perfect and the pole hitting the box at even high speeds doesnt push it that much, or atleast not enough for it to be a problem.