Rotating Entity Child to another Entity Child
Blitz3D Forums/Blitz3D Programming/Rotating Entity Child to another Entity Child
| ||
Hi All I'm trying to line up prefab entities with each other but it doesn't work all the time. Each entity have children which are the points that require to be lined up by rotating the main entity only this is want I'm trying to achieve Bake Your Own 3D Dungeons With Procedural Recipes This is the code I have to position and rotate the entity OK Ive converted some of the code on the page above but the angles still are not right. Here is the code. |
| ||
It's difficult to grasp without a visualisation. Please post one or more screenshots. |
| ||
Here is one using the top code.![]() The color cubes show the entities that are joined but the angle on most of them are wrong. here is another one using the same code and most of them are fine and lined up correctly ![]() |
| ||
Thank you. It's easier to understand now. It seems the problem lies with the alignment. After some reflecting, the world-space yaw rotation of an exit of a module is the world-space yaw rotation of the module plus the local yaw rotation that the exit has in relation to the module. Therefore, to make the exit be aligned to some specific world-space yaw rotation, first we need to calculate that relative rotation of the exit and then rotate the module so it makes that exit align to what we want. Then you can move the module to the target exit and offset the module by a certain amount so one exit is placed on the other. If I'm not mistaken, the code should be the following: ;Consider module "A" and module "B." ;We want to move and align a certain exit of module A with a certain exit of module B. ;First, rotate the module A so that the exit from this module is ;aligned (in the opposite direction) to the target exit from module B, in the yaw axis. Local targetExitYaw# = EntityYaw( exitB, True ) + 180 ;World space, and opposite direction. Local newModuleYaw# = EntityYaw( moduleA, True ) + ( targetExitYaw - EntityYaw( exitA, True ) ) RotateEntity( moduleA, 0, newModuleYaw, 0, True ) ;Second, move the module A and offset it so that the exit from this module is on top of the target exit of module B. PositionEntity( moduleA, EntityX( exitB, True ), EntityY( exitB, True ), EntityZ( exitB, True ), True ) Local offsetX# = EntityX( moduleA, True ) - EntityX( exitB, True ) Local offsetY# = EntityY( moduleA, True ) - EntityY( exitB, True ) Local offsetZ# = EntityZ( moduleA, True ) - EntityZ( exitB, True ) TranslateEntity( moduleA, offsetX, offsetY, offsetZ, True ) |
| ||
After changing this linePositionEntity( moduleA, EntityX( exitB, True ), EntityY( exitB, True ), EntityZ( exitB, True ), True )to this PositionEntity( moduleA, EntityX( exitA, True ), EntityY( exitA, True ), EntityZ( exitA, True ), True )I still get the same result maybe my prefab meshes are are wrong as each exit has its own yaw and always points out. Like so 0 -90 -|- 90 180 I will check all my prefab meshes to make sure all the angles a correct. Ive checked all my Prefab meshes and all the angles on them are correct so its has to be code. Ive uploaded my code and media files HERE |
| ||
Ive re-write the code it works better but still get the same problem if anyone can help |
| ||
Admittedly, I only skimmed through the post here, but this may be of use I hope: Assuming there's no transformations to the actual entity(ies)in question with regards to say, TFormPoint etc. |
| ||
Once you have the delta vector you can use AlignToVector and spare the Sqr and ATan calls:Function PointAt( entity, x# = 0.0, y# = 0.0, z# = 0.0 ) Local deltaX# = x - EntityX( entity, True ) Local deltaY# = y - EntityY( entity, True ) Local deltaZ# = z - EntityZ( entity, True ) AlignToVector( entity, deltaX, deltaY, deltaZ, 3 ) End Function |