child entity problem, need help

Blitz3D Forums/Blitz3D Programming/child entity problem, need help

Ok, im trying to spawn a particle at a child objects cords....but the parent object is moveing, and the spawned particles are not, i have tried to use loadanimmesh to retain the cubes that i added, and i renamed them even, but problem is almost like the child entity is not moving with the parent entity

Quick example of what i would like to do is this

mdl=loadanimmesh("mdlname.3ds")

repeat
if keyhit(1) then end

moveentity mdl,1,0,0

create_engine_particle(mdl,"engspawn1")
forever

function create_particle(parent_entity, child_entity_name$)
engspawnref=findchild(parent_entity,child_entity_name$)
x#=entityx(engspawnref)
y#=entityy(engspawnref) etc..

engpart=createsprite()
positionentity engpart,x#,y#,z#
end function

Please help me someone im gonna go crazy :(

Use windowed, debug mode and put in

DebugLog "create_particle: " + str(engspawnref) + " " + str(x) + " " + str(y) + " " + str(z)

(just before "end function") and see what you're getting. Track the position of mdl the same way. Use that information to figure out your typo or whatever is causing the problem.

Ok, found what the problem was.....

b4 was
1) move parent
2) look at child cords and spawn the particle
3) particle not where its supposed to be :(

now working
1) move parent
2) detach child
3) spawn particle
4) reattach child
5) particle where it needs to be :)

for some reason blitz isn't updateing cordinates for entitys that have parents that have moved......workaround was to temporaley remove the entity from the parent..... then put it back when you get done getting the info you need from it.

check the global parameters of your commands ;)

Ok, here is a very basic example of what the problem is, run once with comments, and once without, and then see if you can tell me where the problem is? i know it works with the lines uncommented......just letting others see if they see a variable thats not "global" or "debugged".......not trying to tick anyone off with this, cause i understand you are trying to help, but in this example it is not working the way it should.

Graphics3D 800,600,32,2
SetBuffer BackBuffer()

Global cam=CreateCamera()

Global mcube=CreateCube()

Global scube=CreateCube()
EntityAlpha scube,.5
MoveEntity scube,-4,0,0

EntityParent scube,mcube

MoveEntity cam,0,0,-10

Repeat
	If KeyHit(1) Then End
		
	MoveEntity mcube,0,.01,0
	MoveEntity cam,0,.01,0
	
	TurnEntity mcube,.3,0,0
	
	tmpcube=CreateCube()
	DebugLog("x:>"+Str(EntityX(scube))+" y:>"+Str(EntityY(scube))+" z:>"+Str(EntityZ(scube)))
	
	;EntityParent scube,0
	PositionEntity tmpcube,EntityX(scube),EntityY(scube),EntityZ(scube)
	;EntityParent scube,mcube
	
	ScaleEntity tmpcube,.1,.1,.1
	
	UpdateWorld
	RenderWorld
	Flip
Forever


As Cygnus mentioned, you can use a parameter with EntityX() etc. so that it returns the global, world coords of the entity:

EntityX(scube,1)

Whereas:

EntityX(scube)

returns the the Entity's position *relative* to it's parent.