Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Resolved Making a Door in Unity ECS

Discussion in 'Physics for ECS' started by ZexScal4, Jan 10, 2020.

  1. ZexScal4

    ZexScal4

    Joined:
    May 25, 2018
    Posts:
    8
    How can I make a door in DOTS that has a box collider and a child sphere trigger so that it automatically moves when it detects a player entity in range of it?

    I feel as though when I make a door object with collider and child with a isTrigger PhysicsShape component at conversion the sphere trigger is lost somewhere and I cant find it.

    how does the heirarcy work when converting physics shapes? What happens to child trigger when it is absorbed by parent collider?
     
    NotaNaN likes this.
  2. NotaNaN

    NotaNaN

    Joined:
    Dec 14, 2018
    Posts:
    325
    I would like to know how the GameObject hierarchy works when conversion happens for Physics Shape components as well. For an example of my use case; in my project I wanted to have child colliders for my hurtboxes on my enemies and player. Unfortunately, it seems like during GameObject conversion the colliders are compounded, and there doesn't seem to be any "don't compound colliders" toggle or component to stop it from happening. :(

    Eventually I gave up and tried to write my own Physics Shape component through various means for about five hours (I made my own authoring components and a bunch of systems to no avail). Eventually, I gave up on that too. But I was able to create the collider. I just couldn't get it to hit anything... It was hard to tell what was wrong since the Entity Debugger won't show collider data. :cool:

    Anyway, I would find it massively helpful to know what's going on when it comes to to the conversion process and colliders and how we are supposed to get around it.
     
  3. thelebaron

    thelebaron

    Joined:
    Jun 2, 2013
    Posts:
    851
    Because child colliders will be removed from a hierarchy(see this thread which I made after tackling this problem myself https://forum.unity.com/threads/any...lso-ignoring-inside-hits.787151/#post-5347062) you will need to come up with a way to get around these restrictions, dealing with linking entities to other entities as you will most likely need at least two - one for the trigger, one for the collider(I also have my door as a separate entity so I can use the transform euler components, so thats three entities just for a door).
    I found it best to create both physics entities inside my authoring component, as what happens with PhysicsShapes when they get deparented from a hierarchy as far as positioning or even just conversion is something I'm personally not too versed with for the time being, and I don't trust it to use it.
    heres my implementation, aside from playertag(which is just an empty tag component) I think it should work if you just replace that but I havent done anything special to it so if it doesnt then whatever :p
    https://gist.github.com/thelebaron/67ac2e81ffe947ee26ae5365dbbe3a84

    The general idea is: create two separate entities in conversion for the trigger and collider, and have the main authored entity drive the translation and rotation of both of them.

    also note Im not 100% sure on how a physics mass is supposed to be created, kinda assuming what Im doing isnt quite correct but it works for my use
     
    Last edited: Jan 11, 2020
  4. NotaNaN

    NotaNaN

    Joined:
    Dec 14, 2018
    Posts:
    325
    Thank you so much for the explanation and the code snippet! After making some modifications to my Authoring Components -- they worked flawlessly. Which, I have to say, I am really happy about. Your code also contained some things I myself have not seen or used before, so cheers to learning something new! Most notably, I never could figure out how to get a reference to the PhysicsCategoryTags... But your code finally showed me how to do it. (It was in the Physics.Authoring namespace... Never would have thought that). ;)

    Anyway, thanks for the assistance and answer! Hopefully Unity will come up with a more standard / simple way of making non-compound colliders in the future. Until then... This is the next best thing! :D

    Cheers! (Apparently saying "cheers" to express good wishes at the end of a conversation is a British thing... And I'm not British. But of course, that never stopped me, though...) :rolleyes:
     
    thelebaron and hippocoder like this.
  5. ZexScal4

    ZexScal4

    Joined:
    May 25, 2018
    Posts:
    8
    Thank you for teaching me this.
     
    thelebaron likes this.
  6. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Cheers :D
     
    NotaNaN and steveeHavok like this.
  7. anhnguyennh02

    anhnguyennh02

    Joined:
    Jun 1, 2023
    Posts:
    1
    Thank you.
    I found the solution for my problem "Can't find the Physics Body component". So I have to create the Object in Subscene cause it will be an entity to use Entity Physics
     
    daniel-holz likes this.