1. Post #1
    S W
    S W's Avatar
    May 2010
    316 Posts
    I would like to check to see if two entities are colliding and I am unsure how. I dont care if the two entities are touching, they have to physically be partially inside of eachother.

    I tried the method below but it will only work for square objects that aren't at an odd angle.

    local pos = self.GhostProp:GetPos()
    local min = self.GhostProp:LocalToWorld((self.GhostProp:OBBMins()+Vector(1.5,1.5,1.5)))
    local max = self.GhostProp:LocalToWorld((self.GhostProp:OBBMaxs()-Vector(1.5,1.5,1.5)))
    for i,v in pairs (ents.FindInBox(min, max)) do
       --code
    end
    


    I did look into the physObj:IsPenetrating function but I kept getting this error when trying to use it. "Tried to use invalid object (type IPhysicsObject) (Object was NULL or not of the right type)"

    Any ideas on how to check this?

  2. Post #2

  3. Post #3
    Gold Member
    ralle105's Avatar
    October 2005
    4,648 Posts
    PhysObj.IsPenetrating errors because your ghost props don't have any real physics.
    What are you trying to do exactly?

  4. Post #4
    S W
    S W's Avatar
    May 2010
    316 Posts
    I have a prop spawner SWEP which can spawn a prop wherever I am pointing. This SWEP shows a ghost prop as a preview. I do not want the player to be able to spawn a prop if it will intersect with another prop upon spawning.

    The props that are spawned freeze the moment they are spawned, so it isn't like Sandbox where the props will just slide out from one another.

  5. Post #5
    Gold Member
    ralle105's Avatar
    October 2005
    4,648 Posts
    You could spawn the prop and remove it if it's penetrating something, or you could do what you're doing in the OP but with the AABB.

    The later is obviously easier to implement.

  6. Post #6
    S W
    S W's Avatar
    May 2010
    316 Posts
    The problem is I don't know how to check if it is penetrating.
    With AABB, that isn't the problem with the function I posted above. It is the FindInBox. Think about if you had a fence that was angled at 45 degrees. You'd want to be able to spawn another fence angled at 45 degrees on top of that one, but with the FindInBox the ghost fence will be in the box. Look at the picture below for what I mean. Red is the fence and the black is the box it is looking in for ents.



    Although you are correct that I should be using AABB in that function as a rectangular box rotated 90 degrees will screw it up. Although anything that is rotated at any angled besides a multiple of 90 will mess it up due to the findInBox.

  7. Post #7
    S W
    S W's Avatar
    May 2010
    316 Posts
    Any other ideas?

    Edited:

    Oh, I should say that the prop is a SENT so I can use functions such as Touch but I havent figured out anyway that could be useful as I only care if it is actually intersecting the other prop. Maybe there are other functions that are part of the ENT library?