Jump to content

Prim Auto Align Script wanted.


Marlon Wulluf
 Share

You are about to reply to a thread that has been inactive for 2112 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

OK, this is what I'm looking for,,,, I would like to be able to auto align objects just by clicking one of the faces of one object and a face of another object and they would 'snap' into place and auto align,,,, one example would be building lengthy tunnels, I would rez 2 tunnels, click the face of one of the tunnel entrances which would glow, and clicking again to cancel, then click the face of the other tunnel entrance, and the 2nd object would rotate and move to align itself with the 1st object, then I would rez a 3rd tunnel, click the face of the existing tunnel to where the 3rd tunnel would need to be placed, then click the face of the 3rd tunnel entrance, and it would rotate if needed and move to align with the rest of the tunnels.

I know it involves an Einstein load of math, including trig, which I'm literally useless at, hence the request of a script that can do that.

Edited by Marlon Wulluf
Link to comment
Share on other sites

It doesn't seem too difficult or math-y, really the most important part is to define what a "face" is.

  • These pieces are probably mesh, right?
  • Do they have conveniently placed faces to be clicked on?
  • Are those faces facing directly away from the center of the object?
  • Do you even need to use the actual faces of the mesh?

 

  • To make the script as multi-purpose as possible, I would use llDetectedTouchPos (so no real faces are required) and figure out which way that is from the object's center (with some flattening). Do that for the second object as well.
  • Then these objects would communicate so they know where / how big they are, and which directions were clicked.
  • Then the second object would rotate so that the clicked directions are opposite of each other and move into place, which is the first object's position, offset with half of its width in the direction that was clicked.

This is mostly just subtracting vectors from each other, besides the one rotation. (And the communication part, which probably takes most work to set up.)

I know this is all just theory, but if you can script, this should get you started. (Or whoever is interested in trying.)
Or if you want someone to completely script this for you, there's a Commerce section on the forum.

Edited by Wulfie Reanimator
Link to comment
Share on other sites

Objects are pure prim, and the linksets have a single child prim for the alignment.

One of the objects is a 3 way T intersection, and if I wanted to align the section on the leg of the T to the existing rezzed tunnels, then I would first click the face of the exposed end of the tunnel entrance,,, then click the face of the bottom of the leg of the T, then no matter what rotation the T section is,,, it will auto align so that the leg of the T would face the existing tunnel entrance, and them move to align on the same X, Y and Z axis as the child prim on the end of the tunnel linkset.

EG

I have 1 straight tunnel with clickable faces at both ends, I also have a T section with clickable faces on each of the ends, I also have a curved tunnel with clickable faces at both ends, etc etc, now I rez the straight tunnel, click a face at one of the ends,,,, this will then glow to show it's selected,,,, then I would rez a T section, then click on one of the faces at one of the ends, and the T section would move and align its self to the end of the already rezzed tunnel, and the faces that were selected would stop glowing, till the next time a section is to be added.

So, in affect which ever object face is clicked first, is the object that the other object would align to, so in other worlds, clicking the face on object 1 then clicking the face on object 2 would align object 2 to object 1, but if I clicked object 2 first, then any other object that is clicked would align to object 2.

This is what I'm looking for in the script or scripts.

Edited by Marlon Wulluf
Link to comment
Share on other sites

7 hours ago, Marlon Wulluf said:

Objects are pure prim, and the linksets have a single child prim for the alignment.

So you are using child prims for alignment, not just a face. This makes positioning things a lot easier since you'll be able to use the link position from the first object and just move the second object by it's link directly on it.

You'd probably only need one script written that can then be put in every piece you want to align anf it will work the same regardless of scale or shape. (Assuming they are all built to snap at equal degrees like every 90 or 45.)

There should also be an easy way to delete the scripts, like automatically after the alignment, with a chat command, or just manually selecting every piece and removing scripts from selection. 

Link to comment
Share on other sites

OK, I'm using completely separate linksets,,, 1 set is a tunnel with 2 hollowed prims, 1 at each end of the tunnel, the tunnel itself is root and the end prims are children, the other objects (T section and curved tunnel), not linked to the tunnel, but as separate objects, have the same hollowed prim at the ends of the objects,,, EG, the T section would have 3 hollowed prims 1 at each end, as children to the root prim which would be one of the center prims of the T section, the idea would be to touch the outer face of one of those child prims and it would glow to show selected,,,, then on another completely separate object linkset, I would touch the outside face of another child prim and the 2nd object would move into alignment with the first object that has the face glowing, but there's a difference, if I touched the outer face of any point of the T section then it becomes stationary and when I touch the outer face of the tunnel, then the tunnel not the T section would move into alignment, but if I touched the outer face of the tunnel first, then touched the outer face of one of the T section entrances, then the tunnel would be stationary and the T section would move into alignment.

I bought a space station kit that does just that, rez the main hub, then click on one of the door outer rim faces, and rez another section, then click on the outer face of the 2nd section's door, and the 2nd section will move and align itself with the hub,   you do this all the sections you want to add to the space station, which gave me an idea on perfectly aligning prims or creating modular builds that would align perfectly without using the object editing tools, but the station scripts are no mod.

Link to comment
Share on other sites

They say video say more, than trying to explain in text :) ,,,,,,the below link is to a short video I created, demonstrating what I want the script to do,,,, bare in mind, the 2 objects are completely separate and are not linked to each other, and each module has only 1 script in it's root prim, and is part of the afore mentioned space station where the scripts are no mod.

 

https://www.dropbox.com/s/gt52u67yjpf1v3n/Auto-Align.avi?dl=0

Link to comment
Share on other sites

If I properly understand what you want to do, you already know the position and rotation, relative to the main unit, you want the module to occupy.    That's pretty simple -- just read the position and rotation of the main unit and apply those to the pre-set offset and rotation to calculate the region position and rotation to which the second module needs to move.

Or am I missing something?

Link to comment
Share on other sites

2 hours ago, Innula Zenovka said:

If I properly understand what you want to do, you already know the position and rotation, relative to the main unit, you want the module to occupy.    That's pretty simple -- just read the position and rotation of the main unit and apply those to the pre-set offset and rotation to calculate the region position and rotation to which the second module needs to move.

Or am I missing something?

Yep you're definitely missing that I'm no Einstein :) and trig is not my forte.

Link to comment
Share on other sites

Trig isn't my forte either, but fortunately it's not needed.  It's too late for me to do anything tonight, but I'll try to find time tomorrow to make a simple example.  

First, though, please can you confirm that you're in a position -- or would be if you had the tools -- to position the units as you want them to be, and then store the relevant data for future use, when you (or someone else) needs to be able to touch the objects and make them jump into the position and rotation that you've stored?

Link to comment
Share on other sites

@Marlon WullufAssuming I was correct, and that you're able to position the objects as you want them, and then store the relevant details by hard-coding them, here's how to do the calculations (no trig involved).   I'm going to refer to the main unit, the space station, as the "Main Object" and to the child unit, the module that docks with it, as the "Child Object".

This is how faux rezzers work, btw.   Obviously the scripts are very different, but the principle and calculations are the same.

First, to read the positions, put this script in the Main Object

//PLACE IN MAIN OBJECT TO READ CHILD OBJECT'S OFFSET AND ROTATION IN RELATION TO MAIN OBJECT

integer iChannel = -67341870;

default
{
    state_entry()
    {
        llListen(iChannel, "","","");
    }

    listen(integer channel, string name, key id, string message)
    {
        list temp = llGetObjectDetails(id, [OBJECT_POS,OBJECT_ROT]);//Read region position and rotation of child object
        vector vMyPos = llGetPos();//Main object's position
        rotation rMyRot = llGetRot();//Main object's rotation
        vector vChildPos = llList2Vector(temp, 0);//Child object's position
        rotation rChildRot = llList2Rot(temp, 1);//Child object's rotation

        vector vOffset = (vChildPos - vMyPos)/rMyRot; //calculate how far the child object is from the main object, discounting the main object's rotation
        //that is, the offset when the main object is rotated at <0.0,0.0,0.0>
        rChildRot = rChildRot / rMyRot;//calculate the child object's rotation when the main object is rotated at  <0.0,0.0,0.0>
        llOwnerSay("child object's offset is "+(string)vOffset);
        llOwnerSay("child object's rotation is "+(string)rChildRot);

    }
}

then place this script in the child object, and then touch the child object, to make it announce itself to the main object.

//PLACE IN CHILD OBJECT TO MAKE IT ANNOUNCE ITSELF TO THE MAIN OBJECT
integer iChannel = -67341870;

default{
    touch_start(integer num_detected)
    {
        llRegionSay(iChannel,"boo");
    }
}

Touch the child object, and the main object should chat out the desired offset and rotation.   Make a note of these, and remove the scripts from both objects.    Then enter the offset and rotation you've just noted into this script, which you should then place in the child object, the module that is to dock with the space station:

My example is for two 1 metre cubes, with the faces on their positive X axes (face 2) touching.

PLACE THIS IN THE CHILD OBJECT TO MAKE IT MOVE INTO THE DESIRED POSITION AND ROTATION IN RELATION TO THE MAIN OBJECT
integer iChannel = -67341870;
rotation rRot = <0.0, 0.0, -1.0, 0.0>;//fill in desired rotation here
vector vOffset = <1.0,0.0,0.0>;//fill in desired offset here

default
{
    state_entry()
    {
        llListen(iChannel, "","","");
    }

    touch_start(integer num_detected)
    {
        llRegionSay(iChannel,"boo");   
    }

    listen(integer channel, string name, key id, string message)
    {
        list temp = llGetObjectDetails(id,[OBJECT_POS,OBJECT_ROT]);
        vector vObjectPos = llList2Vector(temp, 0);//read target object's position
        rotation rObjectRot = llList2Rot(temp,1);//and rotation
        vector vTargetPos = vObjectPos + vOffset * rObjectRot;//calculate the target position, using the target object's frame of rotational reference, not the region's (i.e. relative to the target object)
        rotation rTargetRot = rRot * rObjectRot;//calculate the child object's desired rotation, using the target object's frame of rotational reference
        llSetRegionPos(vTargetPos);//move to the target position
        llSetRot(rTargetRot);//and rotate to face in appropriate direction 
    }
}

and put this in the main object

//PLACE THIS IN THE MAIN OBJECT, SO THE CHILD OBJECT CAN FIND IT
integer iChannel = -67341870;

default
{
    state_entry()
    {
        llListen(iChannel, "","","");
    }

    listen(integer channel, string name, key id, string message)
    {
        llRegionSayTo(id, channel, "boo");
    }
}

Then, when you've done all that, touch the child object, the module, and it should move into the desired position relative to the main object and rotate itself to the desired rotation.

  • Thanks 1
Link to comment
Share on other sites

@Innula Zenovka Thanks for the scripts, but using 4 scripts and to write down data wouldn't be feasible for other people to do, hence the requirement of just clicking one face on the main prim/object then clicking a face on the child prim/object and they would auto align without entering anything into the scripts.

I had to modify them a little and even though you supplied 4 scripts, I narrowed it down to just 2, the main and the child, and instead of the main saying the offset and the rotation of the child, they are first converted into a list, then to a string for sending to the child using llRegionSay,,,, then in the child script, the conversion is reversed, and the variable vTargetPos  is calculated with the offset received from the main and the variable rTargetRot is calculated also to include rRot from the main, then the usual movement control is used, but it don't want to work, there is no movement.

These are the 2 scripts I modified:-

//PLACE IN MASTER OBJECT TO READ SLAVE OBJECT'S OFFSET AND ROTATION IN RELATION TO MASTER OBJECT

integer iChannel = -67341870;
integer cChannel = -27465144;

list objDetails;

default
{
    state_entry()
    {
        llListen(iChannel, "","","");
    }

    listen(integer channel, string name, key id, string message)
    {
        list temp = llGetObjectDetails(id, [OBJECT_POS,OBJECT_ROT]);//Read region position and rotation of child object
        vector vMyPos = llGetPos();//Main object's position
        rotation rMyRot = llGetRot();//Main object's rotation
        vector vChildPos = llList2Vector(temp, 0);//Child object's position
        rotation rChildRot = llList2Rot(temp, 1);//Child object's rotation

        vector vOffset = (vChildPos - vMyPos)/rMyRot; //calculate how far the child object is from the main object, discounting the main object's rotation
        //that is, the offset when the main object is rotated at <0.0,0.0,0.0>
        rChildRot = rChildRot / rMyRot;//calculate the child object's rotation when the main object is rotated at  <0.0,0.0,0.0>
        objDetails = [vOffset, rChildRot];
        string objSend = llDumpList2String(objDetails,"|"); // Convert to a string ready for sending to the slave prim.
        llRegionSay(cChannel, objSend); // Send the Slave offset and rotation to the Slave.

    }
}

And this one for the child prim:-

//PLACE THIS IN THE CHILD OBJECT TO MAKE IT MOVE INTO THE DESIRED POSITION AND ROTATION IN RELATION TO THE MAIN OBJECT
integer iChannel = -67341870;
integer cChannel = -27465144;

list objDetails;

rotation rRot; // = <0.0, 0.0, -1.0, 0.0>; //fill in desired rotation here, rotation provided by the Master prim
vector vOffset; // = <1.0,0.0,0.0>; //fill in desired offset here, offset provided by the Master prim.

default
{
    state_entry()
    {
        llListen(iChannel, "","","");
        llListen(cChannel, "","","");
    }

    touch_start(integer num_detected)
    {
        llRegionSay(iChannel,"boo");   
    }

    listen(integer channel, string name, key id, string message)
    {
        list temp = llGetObjectDetails(id,[OBJECT_POS,OBJECT_ROT]);
        vector vObjectPos = llList2Vector(temp, 0);//read target object's position
        rotation rObjectRot = llList2Rot(temp,1);//and rotation
//        vector vTargetPos = vObjectPos + vOffset * rObjectRot;//calculate the target position, using the target object's frame of rotational reference, not the region's (i.e. relative to the target object)
//        rotation rTargetRot = rRot * rObjectRot;//calculate the child object's desired rotation, using the target object's frame of rotational reference
        if (channel == cChannel)
        {
            objDetails = llParseString2List(message,["|"],[]); // Convert the incoming text back into a list.
            vOffset = llList2Vector(objDetails, 0); // Separate the offset from the list.
            rRot = llList2Rot(objDetails, 1); // Separate the rotation from the list.

// Prepare this slave prim for movement and rotation.
            vector vTargetPos = vObjectPos + vOffset * rObjectRot;
            rotation rTargetRot = rRot * rObjectRot;
            llSay(0, (string)vOffset); // Used for debugging
            llSay(0, (string)rRot); // Used for debugging
//            llSay(0, llList2String(objDetails, 0));
//            llSay(0, llList2String(objDetails, 1));
            llSetRegionPos(vTargetPos);//move to the target position
            llSetRot(rTargetRot);//and rotate to face in appropriate direction 
        }
    }
}

 

Link to comment
Share on other sites

@Marlon Wulluf  I'm sorry for not making myself clearer.   All the finished product needs is my final two scripts.   The first two are simply there to enable you to calculate rotation rRot  and  vector vOffset to put in the "slave script".   

Then all you need in the "master" script is something to make the main unit announce its presence to the slave unit.   It doesn't need to send anything to the slave unit -- the slave script reads the master unit's uuid in the listen event, uses that to discover the main unit's position and rotation on the region, and then does the necessary calculations.

All the finished product needs are my last two scripts -- throw away the first two once you've used them to calculate the offset and rotation to put in the final slave script.

Link to comment
Share on other sites

10 hours ago, Innula Zenovka said:

@Marlon Wulluf  I'm sorry for not making myself clearer.   All the finished product needs is my final two scripts.   The first two are simply there to enable you to calculate rotation rRot  and  vector vOffset to put in the "slave script".   

Then all you need in the "master" script is something to make the main unit announce its presence to the slave unit.   It doesn't need to send anything to the slave unit -- the slave script reads the master unit's uuid in the listen event, uses that to discover the main unit's position and rotation on the region, and then does the necessary calculations.

All the finished product needs are my last two scripts -- throw away the first two once you've used them to calculate the offset and rotation to put in the final slave script.

I realize that, but that's based on the slave prim being in the exact rotation and position every time, so that the offset and rotation is the same,,,, have a look at the video again,,,, I touched the left object and it lit up, then I touched the right object and it then aligned with the face of the right object, it doesn't matter how close or far the 2nd object is or how it's rotated, it will still line up with the 1st object, without editing anything.

I'm not trying to sound sarcastic, but did you try the scripts inworld?  I did, and I even did it as you suggested, and the slave prim didn't move an inch.

Edited by Marlon Wulluf
Link to comment
Share on other sites

:@Marlon Wulluf  Have you tried my scripts?   The whole point of the calculations in the very first one, 

//PLACE IN MAIN OBJECT TO READ CHILD OBJECT'S OFFSET AND ROTATION IN RELATION TO MAIN OBJECT

is to calculate what the desired position and rotation are for the slave unit when it's in position, discounting the rotation of the master unit (i.e. its offset and rotation when the master unit is rotated at <0,0.0>.

The calculations in the third script, 

//PLACE THIS IN THE CHILD OBJECT TO MAKE IT MOVE INTO THE DESIRED POSITION AND ROTATION IN RELATION TO THE MAIN OBJECT

are to find the position and rotation of the master unit, wherever it happens to be on the region, calculate the offset translated by the master unit's rotation, move there, and then rotate into the desired rotation, again translated by the master unit's rotation.

When I tested them before posting this, they appeared to me to be working as intended.  If they're not, then please tell me what they're doing wrong.   

With mine you have to touch the child object to make it ask the master object to announce itself, but that's easy to change if you want to -- I was just trying to explain how to do the necessary calculations.

See my animated gifs:  

https://gyazo.com/5423616c77a75299d446706d557c85b6

https://gyazo.com/488ddb18ada61dae2d2770915430008e

 

Edited by Innula Zenovka
Link to comment
Share on other sites

@Innula Zenovka Have a look at this video screenshot I took, excuse the quality, as my viewer was using up most of the GFX memory and camstudio didn't like it when trying to record at a higher resolution, anyway,,,, this is the procedure, I took in following your suggestion to the letter, and as you can see at the end when I move the pointer around on the slave prim, I'm trying to click it, and it's not doing anything.

Procedure I used to attempt prim auto align.

The previous video:- https://www.dropbox.com/s/gt52u67yjpf1v3n/Auto-Align.avi?dl=0 should have been self explanatory.

Edited by Marlon Wulluf
Link to comment
Share on other sites

Don't try getting what you want out of this forum, I've learned people are only allowed to get what 2 or 3 people on the forum want them to get, and if you think they might not be completely right and that their opinions do not trump yours, you'll only end up being argued out of having any further interest.

For my part I'll try to use some of my precious spare time inworld to find a way to do this, and if I have any success, I'll just send it to you in there. I think the idea is a good one, and it could actually help with some of what I'm doing currently in a building project, so I have real incentive to try, at least. Auto-aligning via a simple script would be a great utility.

I spend most of my time inworld (read, not on forums, but actually in SL) nowadays, and there seems to be a huge divide between what actually works and is practical and what people tend to throw together and post in here as quickly as they can, often just to prove things to the people asking for help.

If you get real help here, power to you, but the prevailing philosophy of making things as complicated as possible for the learner or for people wanting help with a script without having to pay one of the resident, entrenched "experts" makes it difficult for many, I've noticed.

For what it's worth, I had no trouble knowing what you were trying to do by reading your first post. You're more than clear, don't let anything said in here make you feel like you're not good enough to work this all out on your own with just the smallest bit of help in finding your way.

Edited by PheebyKatz
Link to comment
Share on other sites

6 hours ago, Marlon Wulluf said:

@Innula Zenovka Have a look at this video screenshot I took, excuse the quality, as my viewer was using up most of the GFX memory and camstudio didn't like it when trying to record at a higher resolution, anyway,,,, this is the procedure, I took in following your suggestion to the letter, and as you can see at the end when I move the pointer around on the slave prim, I'm trying to click it, and it's not doing anything.

Procedure I used to attempt prim auto align.

The previous video:- https://www.dropbox.com/s/gt52u67yjpf1v3n/Auto-Align.avi?dl=0 should have been self explanatory.

@Marlon Wulluf I see what's happened.

I'm sorry, it's my fault for not explaining more clearly.  Sorry.    When you read the positions using the first pair of scripts, you have to read them with the two objects positioned as you want to be.   That records the desired position and rotation for the child object.   Obviously if you record the positions with them placed randomly, it's not going to work.   

I thought you would realise that from the way I described it, but I should have spelled it out.  

If you try it again, this time recording the position you actually want the Slave prim to be in relation to the Master, rather than some random position, you should get satisfactory results.

ETA:  Video of me doing it:  https://www.dropbox.com/s/hs1poqthiu1oslr/20180707_052801.mp4?dl=0

Edited by Innula Zenovka
Link to comment
Share on other sites

That's not the point, what if I created  a modular system that just like the video here:- https://www.dropbox.com/s/gt52u67yjpf1v3n/Auto-Align.avi?dl=0  I would need to then, (according to you), rez a module, align it to where I think someone would want it positioned, then record that position, then add it a script, then rez another module and repeat,,,, the idea is NOT to have to record ANY positions or rotations, but for the scripts to do that automatically, just like the short video I posted,,, if that's too hard to understand then there's no point in continuing this futile attempt.

I'll explain this once more.

The idea is to rez a prim or a linkset (watch above video), then TOUCH any face on that prim or linkset, it will either glow or change color to show that side of the prim/object has been selected, THEN, rez another prim/object and touch one of it's faces, and the 2nd object/prim will auto align with the face of the 1st object shown glowing or changed color, regardless of random positioning.

Like the video, the main object has not just that 1 point of contact but could have other points too, and the other object(s) may have multiple points of contact too, meaning not just that one point shown in the video would be touched,,, there could be another point further along that object, and by clicking that would rotate the object and align to that contact point instead.

I can't get much simpler than that.

If you need further example, I suggest going to the marketplace and buying the BBI Forseti modular space station and look for yourself.

Edited by Marlon Wulluf
Link to comment
Share on other sites

What he is asking is, in plain English, basically, "is there a way to use a script to make prims dragged out of inventory (or shift-click-drag copied) automatically position themselves properly, in relation to one another, by clicking on them?"

I'm having trouble myself seeing how placing two scripted prims and recording their positions on the ground is going to help. He's not talking about building a rezzer. He wants to know if prims can be made to act like Legos, or snap-together building blocks, rather than having to copy and paste and readjust positions all the time.

He is asking for help in crafting a builder's utility, something that simplifies the work of editing prims into place relative to each other prior to linking them, making it less tedious, and easier. Clicking the face of one prim, then another face on another prim, would be like applying adhesive to those faces, and the second (third, fourth, etc.) prim would "snap" into place.

It's really a simple idea. If anyone knows how to do it, I would also be interested in knowing.

EDIT: And yes, I realize that if this sort of thing can be done, it's probably already out there, but even if it's not, you never know what's possible until you try.

Edited by PheebyKatz
"third" has a "d" in it.
Link to comment
Share on other sites

@Marlon Wulluf Oh, I see.   You simply need to modify the scripts slightly, and to spend a bit more time setting it up, but the principle is exactly the same -- I was trying to demonstrate how to do the calculations, not write the whole script.

Anyway, you use the first pair of scripts to record all the offsets and rotations the slave module is to use, depending on which face of the master module is touched.  Then store them in a strided list in a modified version of the third script.    This example is for a 1 x 1 x 1 cube, so there's a strided list of six different offsets and rotations to take, depending on which face is touched.

//PLACE THIS IN THE CHILD OBJECT TO MAKE IT MOVE INTO THE DESIRED POSITION AND ROTATION IN RELATION TO THE MAIN OBJECT
integer iChannel = -67341870;
integer iIndex;
integer iStrideLength = 2;

list lOffsetsAndRots =[ //list of possible offsets and rots, depending on which face is touched.
<0.0, 0.0, 1.0>,<0.0, -1.0, 0.0, 0.0>, //if face 0 is touched
<0.0, -1.0, 0.0>,<0.0, 0.0, -1.0, 0.0>,//if face 1 is touched
<1.0, 0.0, 0.0>, <0.0, 0.0, -1.0, 0.0>,//if face 2 is touched
<0.0, 1.0, 0.0>,<0.0, 0.0, -1.0, 0.0>,//if face 3 is touched
<-1.0, 0.0, 0.0>,<0.0, 0.0, -1.0, 0.0>,//if face 4 is touched
<0.0, 0.0, -1.0>,<-1.0, 0.0, -0.0, 0.0>//if face 5 if touched
];
rotation rRot;
vector vOffset;

integer fncStrideCount(list lstSource, integer intStride)
{
  return llGetListLength(lstSource) / intStride;
}

list fncGetStride(list lstSource, integer intIndex, integer intStride)
{
  integer intNumStrides = fncStrideCount(lstSource, intStride);
  
  if (intNumStrides != 0 && intIndex < intNumStrides)
  {
    integer intOffset = intIndex * intStride;
    return llList2List(lstSource, intOffset, intOffset + (intStride - 1));
  }
  return [];
}
default
{
    state_entry()
    {
        llListen(iChannel, "","","");
    }



    listen(integer channel, string name, key id, string message)
    {
        iIndex = (integer)message;//take the index from the face number provided
      //  llOwnerSay("index is "+(string)iIndex);
        list temp = fncGetStride(lOffsetsAndRots, iIndex, iStrideLength);
        vOffset = llList2Vector(temp,0);
      //  llOwnerSay("vOffset is "+(string)vOffset);
        rRot = llList2Rot(temp, 1);
     //   llOwnerSay("rRot is "+(string)rRot);
        temp = llGetObjectDetails(id,[OBJECT_POS,OBJECT_ROT]);
        vector vObjectPos = llList2Vector(temp, 0);//read target object's position
        rotation rObjectRot = llList2Rot(temp,1);//and rotation
        vector vTargetPos = vObjectPos + vOffset * rObjectRot;//calculate the target position, using the target object's frame of rotational reference, not the region's (i.e. relative to the target object)
        rotation rTargetRot = rRot * rObjectRot;//calculate the child object's desired rotation, using the target object's frame of rotational reference
        llSetRegionPos(vTargetPos);//move to the target position
        llSetRot(rTargetRot);//and rotate to face in appropriate direction 
    }
}

Then put this in the Master module.   As you'll see it's a slightly modified version of the original script.   It records the face you touch, lights it up, and then sends the face number to the slave script.   The slave then looks up in lOffsetsAndRots the appropriate offset and rotation for the face number it's been sent, reads the position and rotation of the Master object that sent the message, uses those to calculate the region position and rotation it needs, and then moves into place.

//PLACE THIS IN THE MAIN OBJECT, SO THE CHILD OBJECT CAN FIND IT
integer iChannel = -67341870;
integer iTouchedFace;
default
{
    state_entry()
    {
        llListen(iChannel, "","","");
    }
    
    touch_start(integer num_detected){
        iTouchedFace = llDetectedTouchFace(0);
        llSetLinkPrimitiveParamsFast(LINK_THIS,[PRIM_GLOW,iTouchedFace,0.1]);
        llSetTimerEvent(1.0);
           
    }
    
    timer(){
        llSetTimerEvent(0.0);
        llRegionSay(iChannel, (string)iTouchedFace);
        llSetLinkPrimitiveParamsFast(LINK_THIS,[PRIM_GLOW,iTouchedFace,0.0]); 
        
    }

}

 

See the video here https://www.dropbox.com/s/gdoe82mi53db0u8/20180707_152340.mp4?dl=0

  • Like 1
Link to comment
Share on other sites

@Innula Zenovka OK, now that seems to work, and all I need to do now, is to modify it a bit so that it can be placed into a root prim of a linkset that has touchable faces, IE,  a 4 way tunnel, that has 4 touchable faces, then try to (according to which face of the linked child is touched), get the entire linkset torotate and move into place using the linked child as if it was a single prim.

As I said, I'm useless at Einstein math, and working with vectors and rotations that don't actually match the expected numbers so that a conversion is required, hence a vast knowledge of trig is needed.

Trig is something I hated, even in school, but give me boolean algebra? and I can tell you the truth tables of AND, NAND, OR, NOR, XOR, gates of digital circuits

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 2112 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...