How to move a child nearer to its parent?

Blitz3D Forums/Blitz3D Programming/How to move a child nearer to its parent?

Boiled Sweets(Posted 2006) [#1]
Imagine a child entity that is a distance away from its parent and the parent is turning on the z axis.

Now how can I move the child nearer to the parent as the parent turns?

Picture this its like a clock hands tip moving closer to the center of the clock as the hands go round


Pinete(Posted 2006) [#2]
I suppose you should take a look to the fifth parameter of
MoveEntity... I think maybe has something to do..
it's "true/false", and it defines the kind of movement, global to the world or relative to the parent.
I hope it works for you...


Dreamora(Posted 2006) [#3]
You would have to manually reposition the child ... like:

1) rotate the parent
2) calculate the actual distance parent - child
3) scale x,y,z according to that (modify their position by (parent\x - x) *0.98 etc for example )


Boiled Sweets(Posted 2006) [#4]
MoveEntity entity,x#,y#,z#


Erm 5th paramter?


Boiled Sweets(Posted 2006) [#5]
Dreamora?

eh?

scale?

uh?

OK i can calculate the distance but then how do I know which direction to move the child in?


John Blackledge(Posted 2006) [#6]
PointEntity child, parent
MoveEntity child 0,0,1 ; move 'forwards'


octothorpe(Posted 2006) [#7]
Move the Child "backwards" (-Z) assuming it hasn't been rotated itself.

If the Child is positioned or rotated arbitrarily and you want to keep your rotation, Dreamora's advice is the way to go. I believe this would work:

Function move_entity_toward_parent(child, distance_to_move#)
	parent = GetParent(child)
	current_distance# = EntityDistance(child, parent)
	magnitude_to_retain# = 1 - (distance_to_move / current_distance)
	PositionEntity(child, EntityX(child) * magnitude_to_retain, EntityY(child) * magnitude_to_retain, EntityZ(child) * magnitude_to_retain)
End Function


EDIT: Of course, you could store the rotation and use John Blackledge's suggestion, then restore it after. That might be simpler.


Boiled Sweets(Posted 2006) [#8]
But I cannot point the entity at the parent as it's supposed to be facing the camera


John Blackledge(Posted 2006) [#9]
PointEntity child, parent
MoveEntity child 0,0,1 ; move 'forwards'
PointEntity child, camera


Shambler(Posted 2006) [#10]
Not got the time to test it but isn't a childs parent positioned at 0,0,0 in the childs local coordinates?

In which case moving the child towards 0,0,0 in local coords should move it toward its parent or have I over simplified it? ;)


Yan(Posted 2006) [#11]
Wot shambler said...
Graphics3D 800, 600, 0, 2

cam = CreateCamera()

sphere = CreateSphere()
PositionEntity sphere, 0, 0, 5

cube = CreateCube(sphere)
ScaleEntity cube, 0.5, 0.5, 0.5

Repeat
	Cls
	
	TurnEntity sphere, 0, 0, 1
	PositionEntity cube, 1.5 + Cos(MilliSecs()), 0, 0
	
	RenderWorld
	Flip
Until KeyHit(1)

End



Boiled Sweets(Posted 2006) [#12]
Fred,

awesome! Many thanks


octothorpe(Posted 2006) [#13]
*sigh*

http://blitzbasic.com/Community/topics.php?forum=5