Search Unity

Collision basics

Discussion in 'Editor & General Support' started by islanddreamer, May 29, 2006.

  1. islanddreamer

    islanddreamer

    Joined:
    Apr 29, 2006
    Posts:
    473
    I've imported a background object with mesh collider. Within the mesh collider, the material is set to None (Physic Material) and the Mesh reads ObjectName.

    I've added a character controller to my character, but the collision isn't being recognized.

    What step am I missing?

    Also, what are the correct collision settings for a ground object? Every time I add a Rigidbody, the objects fall through the floor.
     
  2. AaronC

    AaronC

    Joined:
    Mar 6, 2006
    Posts:
    3,552
    Be sure to have a primitive collider on your object that is to collide with your mesh. I dont totally get it but just keep adding colliders until it works. I havent really had any luck with the character controller, so cant help you there. If things dont work how they should theres no harm in rebooting the program now and then
     
  3. jeremyace

    jeremyace

    Joined:
    Oct 12, 2005
    Posts:
    1,661
    Your rigidbody is falling because you have to un-check use gravity in the inspector for the rigidbody component of your object, or check isKinematic which makes the rigidbody only move if you tell it to through scripting.

    I don't think rigidbody is what you want though. I haven't used the character controller, but it should work fine with simple colliders. Are there any colliders on the character controller object? You might have to attatch primitive colliders to the various limbs of your character. Not sure, havent used it.

    Hope that helps 'till someone can tell you exactly how to fix it.
    -Jeremy
     
  4. antenna-tree

    antenna-tree

    Joined:
    Oct 30, 2005
    Posts:
    5,324
    The Character Controller Prefab doesn't use gravity, it uses scripting to simulate gravity by moving the character downwards until it hits a collider.

    Your level mesh doesn't need to have a rigidbody applied to it, it just needs to have a mesh collider applied. The Character Controller Prefab uses a Capsule collider that you can resize to encompass your character.
     
  5. islanddreamer

    islanddreamer

    Joined:
    Apr 29, 2006
    Posts:
    473
    Right. I know how to use the character controller and I imported the mesh with a mesh collider. So what step am I missing?
     
  6. antenna-tree

    antenna-tree

    Joined:
    Oct 30, 2005
    Posts:
    5,324
    I'm not sure then. I've done a number of things with the Character Controller Prefab (FPS and third person) and have never run into the problem of it falling through the "floor". Same with other meshes that have rigidbodies attached, they always properly fall to the ground. The only thing I can think of is that the physics engine does not allow two mesh colliders to collide together. All your rigidbody objects must use primitive colliders.

    Are you trying to do an FPS or a third person game. If it's the latter then you need to parent your character mesh to the Character Controller Prefab. Your character can't have any rigids/colliders... that is all handled by the CCP and your child character just follows along.
     
  7. islanddreamer

    islanddreamer

    Joined:
    Apr 29, 2006
    Posts:
    473
    My character controller doesn't fall through the floor. That's a separate issue.

    I'm doing a third person game. I select the character and then add a dynamics/character controller. Is that what you mean by parenting the mesh to the prefab?

    For the background object, when I import it, I select Mesh Collider.

    The character will still move through the background object.

    If I assign a rigidbody to the background object, it falls through the ground.

    I'm sure I'm just missing a step or failing to tick off the right box...
     
  8. antenna-tree

    antenna-tree

    Joined:
    Oct 30, 2005
    Posts:
    5,324
    No, you need to create the CCP and then make your character a child of that.

    This has to do with the fact that two mesh colliders won't physically interact. Don't assign any rigidbody anything to your character mesh. The collisions are handled by the capsule collider in the CCP.

    Stop assingning an RB to the background object... it doesn't need it. It just needs the mesh collider. Try this example for setting up a 3rd person scene... http://forum.otee.dk/viewtopic.php?p=7349&highlight=#7349
     
  9. islanddreamer

    islanddreamer

    Joined:
    Apr 29, 2006
    Posts:
    473
    Still no luck.

    Here's a screen shot that shows the character controller prefab in the Scene View and its corresponding settings in the Inspector view.

    The house in the scene is the background mesh with a Mesh Collider.
     
  10. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    You are using the sample move script? I don't think that uses the character controller at all, so it won't do any collision detection. You need to use a script that actually uses the character controller.
     
  11. islanddreamer

    islanddreamer

    Joined:
    Apr 29, 2006
    Posts:
    473
    That would explain it, then! :eek:

    So can anyone describe how (or better yet provide a snippet of code) to get the character to recognize its controller's collisions?

    This seems like such a basic requirement; shouldn't it just be a tick box that you switch on whenever you add a dynamics component to any object?
     
  12. antenna-tree

    antenna-tree

    Joined:
    Oct 30, 2005
    Posts:
    5,324
    The SampleMoveScript uses "Transform.Translate" to move the character. You need to use "CharacterController.Move". You can try modifying the FPSWalker script (which is initially part of the First Person Controller Prefab), or look at the Goober character in the Character-Animation examples (1.5b) to see how it's scripted there, or this Goober for another way to do a third person scene.