Check if vector is in 3d CUBE

Hi all. I am trying to check collision with hitbox through npc init.lua, but i don’t understand how to make it properly. With rotating 0 all will be normal, but bone rotate and all works bad. It’s code to draw hitbox part(to show you that my way to find all parts is valid):


function ENT:Draw()	
	self.Entity:DrawModel()
	
	local TEMP_HeadMin, TEMP_HeadMax = self:GetHitBoxBounds( 16, 0 )
	local TEMP_HeadPos, TEMP_HeadAng = self:GetBonePosition(self:LookupBone("CHR_LCalf"))

	local TEMP_HeadStart = {}
	local TEMP_HeadEnd = {}
	
	
	table.insert(TEMP_HeadStart,Vector(TEMP_HeadMax.x,TEMP_HeadMin.y,TEMP_HeadMin.z))
	table.insert(TEMP_HeadEnd,Vector(TEMP_HeadMin.x,TEMP_HeadMin.y,TEMP_HeadMin.z)) 
	
	table.insert(TEMP_HeadStart,Vector(TEMP_HeadMax.x,TEMP_HeadMax.y,TEMP_HeadMin.z))
	table.insert(TEMP_HeadEnd,Vector(TEMP_HeadMin.x,TEMP_HeadMax.y,TEMP_HeadMin.z))
	
	table.insert(TEMP_HeadStart,Vector(TEMP_HeadMax.x,TEMP_HeadMax.y,TEMP_HeadMax.z))
	table.insert(TEMP_HeadEnd,Vector(TEMP_HeadMin.x,TEMP_HeadMax.y,TEMP_HeadMax.z))
	
	table.insert(TEMP_HeadStart,Vector(TEMP_HeadMax.x,TEMP_HeadMin.y,TEMP_HeadMax.z))
	table.insert(TEMP_HeadEnd,Vector(TEMP_HeadMin.x,TEMP_HeadMin.y,TEMP_HeadMax.z))
	
	
	
	table.insert(TEMP_HeadStart,Vector(TEMP_HeadMax.x,TEMP_HeadMin.y,TEMP_HeadMin.z))
	table.insert(TEMP_HeadEnd,Vector(TEMP_HeadMax.x,TEMP_HeadMax.y,TEMP_HeadMin.z))
	
	table.insert(TEMP_HeadStart,Vector(TEMP_HeadMax.x,TEMP_HeadMin.y,TEMP_HeadMin.z))
	table.insert(TEMP_HeadEnd,Vector(TEMP_HeadMax.x,TEMP_HeadMin.y,TEMP_HeadMax.z))
	
	table.insert(TEMP_HeadStart,Vector(TEMP_HeadMax.x,TEMP_HeadMax.y,TEMP_HeadMin.z))
	table.insert(TEMP_HeadEnd,Vector(TEMP_HeadMax.x,TEMP_HeadMax.y,TEMP_HeadMax.z))
	
	table.insert(TEMP_HeadStart,Vector(TEMP_HeadMax.x,TEMP_HeadMin.y,TEMP_HeadMax.z))
	table.insert(TEMP_HeadEnd,Vector(TEMP_HeadMax.x,TEMP_HeadMax.y,TEMP_HeadMax.z))
	
	
	
	table.insert(TEMP_HeadStart,Vector(TEMP_HeadMin.x,TEMP_HeadMin.y,TEMP_HeadMin.z))
	table.insert(TEMP_HeadEnd,Vector(TEMP_HeadMin.x,TEMP_HeadMax.y,TEMP_HeadMin.z))
	
	table.insert(TEMP_HeadStart,Vector(TEMP_HeadMin.x,TEMP_HeadMin.y,TEMP_HeadMin.z))
	table.insert(TEMP_HeadEnd,Vector(TEMP_HeadMin.x,TEMP_HeadMin.y,TEMP_HeadMax.z))
	
	table.insert(TEMP_HeadStart,Vector(TEMP_HeadMin.x,TEMP_HeadMax.y,TEMP_HeadMin.z))
	table.insert(TEMP_HeadEnd,Vector(TEMP_HeadMin.x,TEMP_HeadMax.y,TEMP_HeadMax.z))
	
	table.insert(TEMP_HeadStart,Vector(TEMP_HeadMin.x,TEMP_HeadMin.y,TEMP_HeadMax.z))
	table.insert(TEMP_HeadEnd,Vector(TEMP_HeadMin.x,TEMP_HeadMax.y,TEMP_HeadMax.z))
	

	for H=1,#TEMP_HeadStart do
		TEMP_HeadStart[H]:Rotate(TEMP_HeadAng)
		TEMP_HeadEnd[H]:Rotate(TEMP_HeadAng)
	
		render.DrawLine( TEMP_HeadPos+TEMP_HeadStart[H], TEMP_HeadPos+TEMP_HeadEnd[H], Color(255,255,0,255), true )
	end
end

And here is screenshot:

Any ideas?

I’d say it’d probably be easiest to check each value in the vector individually, granted you already have mins and maxs.

No, because for example we have one side rotated like this / / and for example hit was in middle of one side. Result will be False, because it collide with up, but not collide with down.

Rotate the vector backwards and check it if its in between the min and max. Also the rotation must be done around the center of the box.

Yes, remember that you can rotate Vector virtually and check if it’s corners fit.

In other words, you can turn this on the left into this thing on the right:

http://puu.sh/t5Meb/63555c4762.png

Oh, i don’ think that i will get answer D: But anyway i tryed this and it’s work not good. I wanted to do this because i was lazy and don’t want create hitgroups, but when i opened model in HLMV…i discovered that i must create hitboxes by myself, because autogenerated physboxes of more parts looks sadly. Now i just set my npcs self.LastHitbox to last damaged hitbox in ScaleNPCDamage hook and this work fine. With projectiles this work bad (example: crossbow), but i almost decided this problem: i create tracer from damage position to damage position+(damage force100) if self.LastHitbox==0 and after this if hitgroup anyway equal to 0 i create another tracer from inflictor(if it’s not weapon) pos to inflictor pos+(inflictor forward100) and all work almost fine. Another small question: can i make tracer ignore all excluding one entity?