Jump to content

AABB will not detect all entities


Slastraf
 Share

Recommended Posts

If I make an aabb in front of the player's camera like this

	if window:KeyHit(Key.Q) then
		--local model1 = Model:Box() 
		--local model2 = Model:Box() 
		local spellPointMin = Transform:Point(-2,-2,0.1, self.camera, nil)
		local spellPointMax= Transform:Point(2,2,5, self.camera, nil)
		--model1:SetPosition(spellPointMin) 
		--model2:SetPosition(spellPointMax)
		local aabb = AABB(spellPointMin, spellPointMax)
		world:ForEachEntityInAABBDo(aabb,"Callback") 
	end

I believe it will work in the standard fpsplayer script, and it uses various functions like ForEachEntity which should call the global "Callback" function on an entity

the callback function looks as follows (and works):

function Callback(entity,extra)
	--this function needs to be global, for the aabb in the player script (Somewhere around ...Key.Q... line)
	if (entity:GetClass()==Object.ModelClass) then
		if(entity:GetKeyValue("type") == "movEntity") then entity:SetColor(1,0,0)  end
	end
end

And to make a moveable Entity detect I set a key value as above to the entity. 

It works all fine, but only sometimes.

When I walk toward an object with the KeyValue and constantly press q, nothing happens.

However if I then move, and press q again, it works fine. If the angle is right (it sometimes will never work under certain angles no matter if its obfuscated or not)

Here is a video :

Thats it. I hope someone can help me solve this problem, and its not a bug.
Link to comment
Share on other sites

11 hours ago, Lethal Raptor Games said:

Have you enabled debugging of all AABB's?  I'm away from my pc atm but it somthing like camera->debugAABB().

No I have not, but I don't use cpp because I wouldn't know how to set it up. Although if its really necessary I  could. There is no documentation on debugAABB also ?

Link to comment
Share on other sites

I think it would be better to transform the center of the desired bounding box and then give it equal dimensions. The AABB will be aligned to global space, so it is getting squished at some angles, the way you have it now.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

5 hours ago, Josh said:

I think it would be better to transform the center of the desired bounding box and then give it equal dimensions. The AABB will be aligned to global space, so it is getting squished at some angles, the way you have it now.

Do you mean take only the middle point from the Transform:Point() function and then add / substract to make the vectors ? Or do you mean some function I dont know of yet.

Link to comment
Share on other sites

Okay so for everyone who has the same problem in the future, I fixed this by just transforming the origin point and then adding vectors to make each min and max, as josh said.

	-- activate currently selected spell
	--working code
	if window:KeyHit(Key.Q) then
		--local model1 = Model:Box() 
		--local model2 = Model:Box() 
		local p1 = Transform:Point(0,0,2.5, self.camera, nil)
		local pMin = p1 + Vec3(-2,-2,-2.4)
		local pMax = p1 + Vec3(2,2,2.5)
		--model1:SetPosition(spellPointMin) 
		--model2:SetPosition(spellPointMax)
		local aabb = AABB(pMin, pMax)
		world:ForEachEntityInAABBDo(aabb,"Callback") 
	end

 

  • Like 1
  • Haha 1
  • Upvote 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...