findchild and collisions

Blitz3D Forums/Blitz3D Programming/findchild and collisions

PsychicParrot(Posted 2005) [#1]
Ello!

I have a single level .3ds file and I want to findchild different bits of it to add collisions. Problem is, it doesn't seem to be working ... anybody got any idea what I'm missing here?

I load the mesh using:

levelmesh=LoadAnimMesh("level1.3ds")

and use the following to add collisions to the 'track', which is named 'parta,partb and partc'. I know it's finding the children ok and I can even remove the if/name condition without success, which you would think would add collision to all children.


Const playercol = 1
Const levelcol = 2

Function initcollisions()

; Set up collisions for level

	For e = 1 To CountChildren(levelmesh)
		
		ent= GetChild(levelmesh,e)
	
		If Left$(EntityName(ent),4) = "part" 
			EntityType ent,levelcol
			EntityPickMode ent,2
		EndIf
		
	Next
	
	Collisions playercol,levelcol,2,2

End Function



Any help would be appreciated. Thanks all! :)


PsychicParrot(Posted 2005) [#2]
Ahh .. seems you can't linepick an animmesh loaded object, eh? There goes my 'height off the ground' finder then!!

Is this right? Can't you linepick an animmesh?

Ta!


jfk EO-11110(Posted 2005) [#3]
You need to do this in a recursive way since there may be grand-parents etc. that are not direct children. Have a look at this:
http://www.blitzbasic.com/codearcs/codearcs.php?code=1170

You may use a similar method to read all names. In case you are not looking for "Mesh" entities, have a look at the versions.txt for the other EntityClass$()es.

At the other hand "FindChild" works trough all generations automaticly, but I agree, when you are searching for parts in names, it's not very useful unless you start a brute force search for some child entity names :)


jfk EO-11110(Posted 2005) [#4]
BTW you CAN pick Animated Meshes, tho only the individual children that are Meshes. With 3DS and .X this works perfectly. With Bones based Vertex Animation (.B3D) the linepicks will recognize only the original (unanimated) shape of the Mesh, even when it's animated. So when your Soldier is lying on the ground, the bullets would still hit him in mid air.

You need to set the entityPickMode for every Mesh Child using the same recursive method I mentioned before.

Since each children has it's own entity handle, I'd suggest to create some kind of top parent array during the loading process, so each mesh has it's top parent handle stored somewhere. This allows both, diffrent fx on diffrent body parts, but also to identify the soldier quickly.


PsychicParrot(Posted 2005) [#5]
Thanks, matey!

Yeah .. I thought I'd be able to get around it by adding the recursive flag to the entitytype, but thats making all my models have the collision instead of just those named 'part'. Ok I'll have a look at the link you sent and try it.

Haven't actually tried EntityClass$ before, so that's something new I learned today :) thanks!

(just got your second post .. thanks again. If I can get down to the right 'level', then, I should be able to fix this in theory!!)


jfk EO-11110(Posted 2005) [#6]
BTW just edited my prev. Post.


PsychicParrot(Posted 2005) [#7]
Ok, thanks so much for that ... all sorted!

I ended up with :

Function initcollisions()

; Set up collisions for level

	For e = 1 To CountChildren(levelmesh)
		
		ent= GetChild(levelmesh,e)
	
				 For i=1 To CountChildren(ent)
					ww=GetChild(ent,i)
					If Instr(EntityName(ww),"part") Then
						EntityType ww,levelcol
						EntityPickMode ww,2
					Else
					
						EntityType ww,stopcol
						
					EndIf
				Next
		
	Next

	Collisions playercol,levelcol,2,2
	Collisions playercol,stopcol,2,3
	
End Function


And now all is good in the world AND the entity picking is working great :)

Nice one, jfk!