Search Unity

Unity alternitive to Triggered Colliders

Discussion in 'Scripting' started by Shiikarii, Dec 20, 2014.

  1. Shiikarii

    Shiikarii

    Joined:
    Feb 6, 2014
    Posts:
    89
    Hey guy's its me again,
    Let me demonstrate something...



    I've been working on my new Swarm System but i have a problem with the Collider!
    if every little ship has got an collider and it's triggered, the system will overflow...

    Unbe22nannt.PNG

    And here is my Question: ""How can i select single units by clicking the mouse, with physics collider or is there maybe a other better solution?"
    Other Question: "Can i write my own Physics in Unity?"

    Waiting for Unity5's Physics is impossible xD, i must do this on my own :p



    My other problem is to Rotate Objects with One Frame?
    Every Little asteroid has got his own Script with an Update Funktion to rotate the Object Randomly on the Z Axis.
    But this needs many CPU usage...maybe with Rigidbody?

    Unbenssannt.PNG

    Unaabenannt.PNG

    Question is: "How can i make this with low CPU usage?"

    -lg Alex
     
  2. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697
    If you just want to select the object, and colliders are eating up too much memory, you could use Bounds.
     
  3. Kirk Clawson

    Kirk Clawson

    Joined:
    Nov 4, 2014
    Posts:
    65
    Regarding the rotation - is there a reason that each asteroid has to handle it's own rotation? Can you not have an asteroid handler class that keeps the full list of all asteroids, and loops through each asteroid. That way you can start to make smart decisions about perhaps not updating every asteroid on every frame. Maybe only do odd numbered asteroids on odd numbered frames or something along those lines.
     
  4. Random_Civilian

    Random_Civilian

    Joined:
    Nov 5, 2014
    Posts:
    55
    Given the amount of objects you have, it probably won't make too much of a difference but have you tried using layers and the collision matrix?
    EDIT: Wilder and messier idea. It appears that ships are close together. You can try to approximate one big colliders for all of them and use guess work to see which one was damaged.
    EDIT2: Building upon the above idea. Have a swarm manager that keeps track of the positions of its ships. Convert clicks to world coordinates and approximate selection with a distance check.
     
    Last edited: Dec 20, 2014
  5. fire7side

    fire7side

    Joined:
    Oct 15, 2012
    Posts:
    1,819
    Maybe you could use larger colliders to activate a group of individual colliders.
     
    Shiikarii likes this.
  6. Random_Civilian

    Random_Civilian

    Joined:
    Nov 5, 2014
    Posts:
    55
    Yup like this solution better
     
  7. MathiasDG

    MathiasDG

    Joined:
    Jul 1, 2014
    Posts:
    114
    if you wanted to avoid unity's colliders, you could use a two dimensional KDTree to keep track of your objects and use your own raycasts on top of that.
    Not sure if the trouble would be worth it.
    And that would not fix the problem with having too many colliders as well, you would still have to group up your objects into bigger colliders.

    A possible trick for the asteroids rotation would be not to really rotate their transform, but to use some animations. You could have a set of a few animations, and randomly select one animation and randomly scale their speed.

    And for that many spaceships you should avoid the update function as much as possible, not sure what you are using, but just make sure you are using Coroutines as much as you can.
     
    Last edited: Dec 21, 2014
  8. Shiikarii

    Shiikarii

    Joined:
    Feb 6, 2014
    Posts:
    89
    i use a complex algorithm for my Spaceship Units as you say avoid the Update function, i'm using many Coroutines ;)


    Guy's, thank you all for helping me ;)
    I think i would use bigger Colliders to to aktive a smaler group of triggers colliders, and for the asteroids i have to find out whats the better solution... animation or one gameobject who is the manager and handles all the asteroids ;)

    -lg Alex