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

Rigidbody character controller problem.

Discussion in 'Scripting' started by leegod, Jun 24, 2010.

Thread Status:
Not open for further replies.
  1. leegod

    leegod

    Joined:
    May 5, 2010
    Posts:
    2,345
    I attached like these,


    Enemy(cube) - rigidbody, box collider

    Enemy(3d character model) - rigidbody, character controller

    Player(3d character model) - rigidbody, character controller

    Player and enemy's missile - rigidbody, box collider


    Missile's rigidbody's mass is 0.2 and all others are 1.

    But when player's missile hit enemy(cube), physics effect(colliding and pushed away by hitted force) works, but when hit enemy(character),

    physics effect does not work and character is still be there.

    Player character also same when hitted by enemy's missile.

    Why?

    And how to fix to all rigidbody existence affected by rigidbody missile?
     
  2. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    Generally, a rigidbody use with a CharacterController will have its Is Kinematic setting switched on, so it will not react to physics, hence the "indestructible" character you are seeing here. One way to handle this is to turn off the Is Kinematic setting just before the explosion happens to enable the character to be affected by the physics.

    One way to get all the colliders within range of an explosion is to use the Physics.OverlapSphere function. This returns all colliders within a given range of a point. You can then use the colliders' rigidbody component to apply the force (rigidbody.AddExplosionForce is an easy way to handle this).
     
  3. leegod

    leegod

    Joined:
    May 5, 2010
    Posts:
    2,345
    Thanks for reply,

    But I can't understand well.

    Enemy character and player character's rigidbody's (Is Kinematic) is turn off state.

    And there are none of turn on that.


    And my missile's script has already script like this

    Code (csharp):
    1.  
    2. function FixedUpdate()
    3. {
    4.     rigidbody.AddForce(transform.forward * beamVelocity,   ForceMode.Acceleration);
    5. }
    6.  
    And I use [Detonator] from unity official resources, for explosion effect when critical hit occur.

    Now, still, if enemy(cube) is hitted by missile or critical detonator, it well be affected by explosion effects, and others physics.

    But, even detonator occur to our player or enemy(character), it remains and does not be affected.
     
  4. DWORD

    DWORD

    Joined:
    Jun 22, 2010
    Posts:
    38
    Delete the character controller and use just rigidbody for movement. The character controller is Kinematic and can't be turned off.
     
  5. leegod

    leegod

    Joined:
    May 5, 2010
    Posts:
    2,345
    Thanks for reply,

    But then, player character can't move, right?

    How to solve then?

    Is there no solution to instantly disable the character controller and take physics effect, and then again get character controller?
     
  6. DWORD

    DWORD

    Joined:
    Jun 22, 2010
    Posts:
    38
    You can control your character through Rigidbody and its better because it can interact with physics.

    Use rigidbody.MovePosition() to move and enable Freeze rotation in the editor(on rigidbody component). Remember to use physics based functions on FixedUpdate() instead of Update()

    Sorry about my english.
     
  7. bsallesp

    bsallesp

    Joined:
    Jun 27, 2021
    Posts:
    1
    Agreed!

    Um using CC, and this has many pros, but one big con: Rigidbody and character controller dont work well in the sabe object.

     
  8. FormalSnake

    FormalSnake

    Joined:
    Oct 26, 2019
    Posts:
    12
    So how do i exactly do it? I know this thread is 11 years old.
     
  9. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,563
    Please don't necro threads. Simply create your own post and ask your own question; preferably with more effort than "how do I exactly do it".

    Code of Conduct

    Thanks.
     
Thread Status:
Not open for further replies.