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

Compound objects collision and response in same frame

Discussion in 'Physics' started by hexdump, Nov 28, 2014.

  1. hexdump

    hexdump

    Joined:
    Dec 29, 2008
    Posts:
    443
    Hi,

    I have been trying for a long time to solve this using built-in unity physics (collisions) capabilities and have always failed. So, I would like to know if anyone could help this time.

    I have two compound objects made of blocks (blocks belonging to same compound object do not overlap). As an example of the type of compound object I use you can check this picture: https://neil.fraser.name/news/2007/sphere3.jpg.

    In my case I have two spheres created this way and are much more simple. They are created from 1x1 blocks.

    I want to be able to move one of the compound objects (spheres) and it collides with the other push the moving one upwards until them doesn't collide. If I had to do this manually I could move the moving sphere 1 block up in a while loop until no collision was reported. The thing is that I would like to use unit physcis because they will be much faster than any code I could write and for a lot of blocks it makes a difference.

    The only way to accomplish this using unity built-in physics is to listen to the OntriggerEnter/OnTriggerStay events in the parent of the compound object hierarchy (the one with the rigid body) and push up the object every frame a bit until I find that all the OntriggerEnter Colliders match OntriggerExit but for this I should have to wait x frames until the moving object stops intersecting the other. I don't want this I want to do it in the same frame.

    Could anybody bring some light on this subject? I would really like someone to help here becasue I think I have tried all I could and I am a bit lost.

    Cheers.
     
    Last edited: Nov 28, 2014
  2. Partel-Lang

    Partel-Lang

    Joined:
    Jan 2, 2013
    Posts:
    2,548
  3. hexdump

    hexdump

    Joined:
    Dec 29, 2008
    Posts:
    443
    Hi,

    I saw there are Sphere and Capsule casting but this is not what I'm looking for. I have a volume that can me anything made of blocks not just a sphere. I need something that could allow to test a compund object physic volume vs another manually.

    Take into account that SphereCasting would not even work if I could only create spheres from blocks, because its volume does not adjust well. I just could use it in a broad phase, but this is another story.

    Cheers.
     
  4. GarBenjamin

    GarBenjamin

    Joined:
    Dec 26, 2013
    Posts:
    7,441
    You've hit on one of the reasons I don't like canned systems. I should be able to check for collisions and such whenever I want to not have them reported to me on a frame by frame basis. So... you could just use ray casting. You should be able to determine which components in your complex object are the "outer layer" and shoot rays out of them. A simpler way would be like @Partel Lang said... only try the SweepTest. If that doesn't work for you then doing multiple individual sphere casts or even ray casts can be used. I only use 2D in Unity but I use raycasting for collisions most of the time.
     
  5. RJ-MacReady

    RJ-MacReady

    Joined:
    Jun 14, 2013
    Posts:
    1,718
    You want advanced stuff? Program advanced stuff.

    I'm doing frame by frame raycasting to avoid collisions, not respond to them, because I need precise control of my characters. It's all quite simple.

    You'll need to build your own mesh on the fly for your volume, iterating through each point and creating a vertex structure like you would in a voxel engine. Then, create a mesh collider and use sweep testing.

    It will be difficult to do, if you're not well versed in vector maths and 3D graphics in general.

    Cheers, m8.
     
  6. RJ-MacReady

    RJ-MacReady

    Joined:
    Jun 14, 2013
    Posts:
    1,718
    I just had an even better idea, just raycast from the center of each block the direction that your larger object is moving, if there any hits you will know about it just make sure that you layer mask off your current object, you could temporarily set its layer to IgnoreRaycast, for example. Honestly that is easy