Finding Child coordinates relative to parent?

Blitz3D Forums/Blitz3D Programming/Finding Child coordinates relative to parent?

Hosh(Posted 2008) [#1]
Is there any way to find a child's relative coordinates to the parent object???

My model ship.3ds is composed of several child entities. I would like bullets to shoot from the location of certain child entities. The only problem is that children entities take on the coordinates of the parent entity.

So when I copy a bullet sprite and name the gun child as its parent, the bullet appears from the center of gun's parent, and not from gun.

CopyEntity( bullet_sprite, gun )    ; Doesn't work...


So then I tried adding... (b is the bullet type)
PositionEntity b\sprite, EntityX(gun,True), EntityY(gun, True), EntityZ(gun,True)

The hope was to position the bullet at the true coordinates of gun, but really this just caused the bullet to appear farther and farther away from the ship when I moved it farther from the world center (0,0,0).

There was no chance to succeed. Looking at my debuglog, EntityX(gun,True) was the same value as EntityX(Ship)

I even tried disconnecting the gun child from ship by assigning it nothing as a parent.

	EntityParent gun, 0 


But this had the exact same effect as the previous fix. The farther I moved the ship from the world center the farther the bullets began to form away from the ship.

So...

Is there anyway to find a child's relative coordinates to the parent object (via local coordinate system or whatever)???


mtnhome3d(Posted 2008) [#2]
if you look in the samples, in the mak directory there's a folder called anim. In side that theres a folder called makbot. the .bb fie shows how to get the locations of different meshes inside one big ine.


Dreamora(Posted 2008) [#3]
entityx, entityy, entityz are always relative to parent unless you specify the "global" parameter to be true.


Hosh(Posted 2008) [#4]
Mayaman,
The anim example in the mak directory is exactly what I needed.

Unfortunately, I was surprised to find that my code is basically identical (except for variable names, etc.). How strange.

I think my problem has to do with the child hierarchy of my model. I made it in Anim8or. Hmmm... I just don't know... I'll have to play with it some more I guess.

Dreamora,
Yeah, I tried setting the global parameter to true. Didn't' work very well. Made the bullets start appearing farther and farther away from the ship the farther I flew away from the world center (0,0,0).


Ross C(Posted 2008) [#5]
Well, as dreamora say, just use entityx() entityy() and entityz() if you want the positions relative to the parent. DON'T use the TRUE flag though, as that will give you world co-ords.

But, i'm confused... Surely you'd want the world co-ords so you could place the bullet at the exact same world co-ords as the gun?

Rememeber, if you using positionentity on a child entity:

PositionEntity Bullet, EntityX(gun,true), EntityY(gun,true), EntityZ(gun,true) , TRUE


You need the TRUE flag on the end of the positionentity command so it will PLACE the entity in the world co-ords, and not it's parents co-ords.


Hosh(Posted 2008) [#6]
Gun's position relative to the parent ship is 0,0,0. So it's located right on the center pivot.

===DEBUG===
EntityX(gun) = 0
EntityY(gun) = 0
EntityZ(gun) = 0

EntityX(gun, true) = Current global X of the parent ship is.
EntityY(gun,true) = same for Y
etc.

Perhaps if I gave it its own pivot it could have local co-ords different than the global co-ords of the parent?

It's very frustrating because looking at the mak sample code, what everyone has suggested should work.

mak=LoadAnimMesh( "mak_running.3ds" )
eyepos=FindChild(mak,"eye")
eyeflare=CopyEntity(flare,eyepos)


I do the same thing.
p\entity is the ship's handle.
gun is the name of the child (e.g. "left_gun")
b\sprite is the sprite graphic of my bullet type
weapon = FindChild(p\entity, gun)
b\sprite=CopyEntity( bullet_sprite, weapon )


But that doesn't work.
The co-ords of gun on my model are the same as the parent.
The co-ords for flare on the mak model are different than the parent.

Thus, using PositionEntity with the True global flag set does not help. Gun's local co-ords are 0,0,0.

So that seems to be the root of the problem.

My model is faulty. The gun child's local co-ords are 0,0,0. This should not be.

If I import the mak model into Anim8or, change nothing, save it, and export it back into the mak sample folder. The flare is no longer properly positioned at the eye child's position. eye's local co-ords become 0,0,0.

Here it is visually



Before I did this, eye's local co-ords actually gave the true local position from mak's main pivot.

So I am more certain than ever that this is Anim8or issue. What do you guys use to model?


mtnhome3d(Posted 2008) [#7]
personally i use maya but thats sorta expensive. i like ac3d and milkshape.


Ross C(Posted 2008) [#8]
You are using positionentity and not moveentity i assume?

Can you show us your whole code for this. It helps to see if something else isn't set right :o)


Hosh(Posted 2008) [#9]
Function CreateBullet.Bullet( p.Player, w.Weapon, gun$ )
  
		b.Bullet=New Bullet
		b\shooter = p\entity

		weapon = FindChild(p\entity, gun)
		b\sprite=CopyEntity( bullet_sprite, weapon ) 
                PositionEntity b\sprite, EntityX(gun,True), EntityY(gun,True), EntityZ(gun,True), True
	
		b\speed = w\speed

	        MoveEntity b\sprite, 0,0,(b\speed*FL\SpeedFactor)*5
		EntityParent b\sprite,0
		EmitSound shoot,b\sprite
		Return b
		
End Function




Ross C(Posted 2008) [#10]
Your finding the child every time you create a bullet? Once you find a child, i'm sure it gets removed from the child list. I'm not sure about that, but i recommend you only do findchild ONCE.

This line:

weapon = FindChild(p\entity, gun)


Should probably be just after your load your mesh. Assign weapon to a Global variable too.


Blitzplotter(Posted 2009) [#11]
@Dreamora:


entityx, entityy, entityz are always relative to parent unless you specify the "global" parameter to be true.


Thats interesting, then further on Ross C states that it will give you world co-ords.


Ross C(Posted 2009) [#12]
I said don't use the true flag to get the co-ords relative to the parent, but use the true flag to position the entity in global space, rather than local to the parent. Shows how good my memory is though. I have no recollection of typing these replies :)


Blitzplotter(Posted 2009) [#13]
Thanks for the extra clarification Ross, when I was initially reading the thread I was still getting a handle on Entity manipulation areas.

.