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

Ontriggerenter

Discussion in 'Scripting' started by tawdry, Feb 4, 2015.

  1. tawdry

    tawdry

    Joined:
    Sep 3, 2014
    Posts:
    1,356
    Hi
    Trying to get a trigger to activate without needing a rigidbody on my character as i don't use physics.He does have a collider attached. The API says ( Note that trigger events are only sent if one of the colliders also has a rigidbody attached.)
    So i attached the rigidbody to the trigger itself but it doesn't work.Then i attached a char controller to my character and it worked.Then i removed the rigidbody from the trigger and it still worked???.
    So with no rigid bodies the trigger works which means that the API statement is wrong?.

    Now i dont really want to use either a rigidbody or char controller how can i get this damn trigger to work?
     
  2. BenZed

    BenZed

    Joined:
    May 29, 2014
    Posts:
    524
    ONE of the colliders must have a rigidbody. I imagine the char controller component has it's own version of a rigidbody embedded inside of it, but they still both require colliders.

    I would just add the rigidbody, set 'IsKinematic' to true, and make sure there are colliders on both.

    If 'isKinematic' is true, it's physics wont be calculated, as it's expecting you to use the kinematic system to move things about.

    The alternative is creating your own triggering system, where you compare positions and imaginary edges and whatnot. Doesn't sound like much fun.
     
  3. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    Sort of. Kinematic rigidbodies can still push things around so some physics calculations are still happening.
     
  4. tawdry

    tawdry

    Joined:
    Sep 3, 2014
    Posts:
    1,356
    I find that even when iskinetic is set to true the physics still do effect for instance if i run into something with iskenetic it causes me to fly into the air or causes the object to be bumped around which does not occur with just colliders.Looks like the char controller is the best option how expensive are char controllers?.
     
  5. Nubz

    Nubz

    Joined:
    Sep 22, 2012
    Posts:
    553
    Every one reads that wrong.

    Also part of it is incorrect since a character controller works also.

    http://docs.unity3d.com/ScriptReference/30_search.html?q=OnTriggerEnter

     
  6. tawdry

    tawdry

    Joined:
    Sep 3, 2014
    Posts:
    1,356
    Be nice if they added a similar effect as u get with the char controller to the navmesh agent .
     
  7. BenZed

    BenZed

    Joined:
    May 29, 2014
    Posts:
    524
    As I said above, the character controller has it's own rigidbody self contained within.

    Anyway, if you arn't using physics, make ALL of your rigidbodies kinematic, that way they wont collide.

    Working scene attached, just so there is no confusion:
     

    Attached Files:

  8. tawdry

    tawdry

    Joined:
    Sep 3, 2014
    Posts:
    1,356
    Just wondering which has the least overhead to performance the char controller with the bottoms removed or the rigidbod. I'm having lots of agents who all need 1 or the other.
     
  9. BenZed

    BenZed

    Joined:
    May 29, 2014
    Posts:
    524
    A rigidbody is without question less resource intensive than a character controller.

    As I've said, the character controller has a self contained rigidbody.
     
  10. tawdry

    tawdry

    Joined:
    Sep 3, 2014
    Posts:
    1,356
    hmm that sucks i think rigidbody gives me hassles because all my stuff is scaled x2 maybe.