Problem with EntityParent et ScaleEntity

Blitz3D Forums/Blitz3D Programming/Problem with EntityParent et ScaleEntity

RepeatUntil(Posted 2004) [#1]
Here is my problem:
- I have an entity, which is not uniformely scale, and which is animated
- I have an other entity that I parent to this entity
- Problem: this entity is also scaled (as soon as I parent it to the scaled animated entity )!!!

This problem is very well described here:
http://www.blitzbasic.co.nz/b3ddocs/command.php?name=entityparent
Some other people already ran into this problem:
http://www.blitzbasic.co.nz/Community/posts.php?topic=37541

But I can not used the solution proposed there (use scaleMesh instead of scaleEntity) because several entities share the same mesh, and I want to scale every entity differently...

I was trying to find for a workaround for hours... Do someone has a solution for me???????

Thanks!


Klaas(Posted 2004) [#2]
why not use a pivot!?
- create a pivot
- parent the scaled mesh to the pivot
- parent the other entity to the pivot
- apply all moves and rotations to the pivot insted of the scaled mesh


Tom(Posted 2004) [#3]
Scaling Child entitys along with their parents is common amongst 3D programs.

Thought of using ScaleMesh instead?


RepeatUntil(Posted 2004) [#4]
@Klaas: that's not possible in my case. In fact I have an entity (a player) and this player has the second entity (a ball) in his hand. And as the player is animated, the ball has to follow the hand of the player. In summary, I do this:
scaleEntity player, 1., 2., 1.
Find the hand (bone) -> pivotHand
animate player
...
entityParent ball, pivotHand
-> And the ball is then scaled!!

I tried to use an intermediate pivot like this:
newPivot = createPivot()
entityParent ball, newPivot
entityParent newPivot, pivotHand
-> The ball is also scaled!!

And, as for your solution, Klaas, I don't see how I can implement it as the ball has to follow the pivot pivotHand, which moves with the animation.

@Tom: as I said, I can't use scaleMesh instead because several entities share the same mesh, and I want to scale every entity differently...

So still no solution.....


RepeatUntil(Posted 2004) [#5]
I tried to use ScaleMesh instead of ScaleEntity, but that's even worse!! As my entity is animated with bones (using milkshape3D), scaleMesh mess up everything : the mesh itself + the animation. My entity is completely deformed!!

So what can I do????????


Ross C(Posted 2004) [#6]
why don't you scale down the other entity, on the factor of how much the parent entity is scaled up?

ScaleEntity Parent,4,6,4

ScaleEntity Child,2,2,2
EntityParent Child,Parent


to...
ScaleEntity Parent,4,6,4

ScaleEntity Child,0.5,0.333,0.5
EntityParent Child,Parent


Take the scale of the child, and divide the number by the parents scale.

ScaleEntity Parent,4,6,4
ScaleEntity Child,2,2,2

x = 2/4
y = 2/6
z = 2/4

That should sort it. The maths might be a bit off, but it should sort the problem :o)


Ross C(Posted 2004) [#7]
Or, why not scale the entities before you parent them?


RepeatUntil(Posted 2004) [#8]
Thanks Ross, I will try your first solution, even if it's not too practical given that the child is parented only from time to time and to different parents (and hence scale).

For your second proposition, I already do that, and the problem is still the same.


jfk EO-11110(Posted 2004) [#9]
This surprises me, I thought if you parent the ball to the hand AFTER scaling the hand, the ball will remain unscaled.
Well maybe I'm wriong, but I have this feeling.

Are you sure you didn't accidently set the parent before.

Probably you should do a renderworld, visualy check the ball, then parent it to the hand, then check again.


RepeatUntil(Posted 2004) [#10]
Yes, I am sure that I didn't parent the ball before. The ball is parented to the hand only when taken by a player, AFTER of course that the player was scaled.


RepeatUntil(Posted 2004) [#11]
Very strange!!!
I did some more tests on this problem.
First I note that the solution of Ross doesn't work.
And now the surprising thing:
- if I parent the ball to the player with NO previous rotation of the ball --> the ball is not scaled, everything is OK
- if I do a rotation first on the ball, and if after I parent the ball to the player --> the ball is scaled, and there is no simple way to anti-scale it (as proposed by Ross)

So, in fact, the child is scaled as soon as its axis are not any more aligned with the one of the player (y axis not any more parallel). That sounds very strange! I don't see any way to unscale the ball easily: I should unscale it after a rotation in its space, but there that's very difficult, and I am not sure it's possible within blitz...


Ross C(Posted 2004) [#12]
See when your doing the scaleentity, have your tried using the global flag when it's parented? It should scale the entity from a world point of view, same with positioning, use the global flag. Does that work?


Ross C(Posted 2004) [#13]
Basically what i see happening with this, is when you scale the parent, the parents actual axis's are scaled too. Not for the parents movement, but for the childs movement. Like, if you scaled the parent 1,2,1, and moved the child one unit, it would move the child two world units. I suggest scaling the parent in a modelling program then loading it in.


Ross C(Posted 2004) [#14]
Well, maybe not actually. Scale your parent as normal, but when positioning and scaling you child, use this

ScaleEntity child,1,2,1,True
PositionEntity child,EntityX(child,True),EntityY(child,True)+1,EntityZ(child,True),True


Position the entity using entityx,y and z with true flags, and just add on which way you want to move them. Does the exact same as move entity, except it's global. Make sure you have the true flag at the very end in too :o)

That seems to work over here.


skidracer(Posted 2004) [#15]
I think it would be more logical to not attach the ball to your scaled player but instead position the ball at the location of the hand each frame using

positionentity ball,entityx(hand,true),entityy(hand,true),entityz(hand,true)

if the ball position is dependent on the orientation of the hand then child a pivot to the hand to get a correct reference point for positioning the ball


RepeatUntil(Posted 2004) [#16]
Finally, I use the solution of skidracer! That works well! Thanks to everyone...