How to move a child nearer to its parent?
Blitz3D Forums/Blitz3D Programming/How to move a child nearer to its parent?
| ||
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 |
| ||
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... |
| ||
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 ) |
| ||
MoveEntity entity,x#,y#,z# Erm 5th paramter? |
| ||
Dreamora? eh? scale? uh? OK i can calculate the distance but then how do I know which direction to move the child in? |
| ||
PointEntity child, parent MoveEntity child 0,0,1 ; move 'forwards' |
| ||
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. |
| ||
But I cannot point the entity at the parent as it's supposed to be facing the camera |
| ||
PointEntity child, parent MoveEntity child 0,0,1 ; move 'forwards' PointEntity child, camera |
| ||
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? ;) |
| ||
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 |
| ||
Fred, awesome! Many thanks |
| ||
*sigh* http://blitzbasic.com/Community/topics.php?forum=5 |