Jump to content

Making prims rotate back and forth


mansoor50
 Share

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

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

Recommended Posts

If you want to move the whole object,  llSetKeyframedMotion is the obvious way to do it.   

If you have to use llTargetOmega (e.g. you're moving a child  prim in a linkset), then I would use a timer, set reverse the llTargetOmega call when the object has completed its movement (as you'll know, the final element in llTargetOmega's parameters is the time, in seconds, it takes to move through one radian, so if you use the lsl constant PI_BY_TWO there, then that's telling it to move through 90 degrees in one second)..

Link to comment
Share on other sites

  • 3 weeks later...

thank u Innula.....

sorry for getting back to u so late....

i tried the KF and it works wonderfully on the prim.

and as usual.. i have questions...:)

i have a fish that i want to do the following:

1. rotate at the bottom of the tank (i did that by linking it to a root prim)

2. i want it to go up, out of the tank then dive back in. (working but not quite..see below)

3. start rotating again 

the code below is in the root prim

for #2,

a. I need to rotate the linked fish 90 so it points up (originally it is horizontal- that is working thru the llsetlinkparam)

b. then the keyframe kicks in - as u can see...it goes up 5m, then the root rotates 180 and comes back down.

my reasoning is that as the root spins, so shd the fish and it shd then show point it downwards.

but the fish is not behaving. with each touch, the orientation of the fish changes.

can u please tell me where am i going wrong?

rot = llEuler2Rot( <0.0,PI_BY_TWO,0.0>);
        llSetLinkPrimitiveParams(2, [ PRIM_ROTATION, rot ]);
        llSetKeyframedMotion([<0.0, 0.0, 5.0>, llEuler2Rot(<0, 0, 0> * DEG_TO_RAD), 5,
		<0.0, 0.0, -5.0>, llEuler2Rot(<180, 0, 0> * DEG_TO_RAD), 5,
		<0,0,0>,llEuler2Rot(<0,0,0>),1],
        [KFM_MODE, KFM_FORWARD]);
        rot = llEuler2Rot( <0.0,0.0,0.0>);
        llSetLinkPrimitiveParams(2, [ PRIM_ROTATION, rot ]);    
        llTargetOmega(<0,0,1>,1.0,.2);
        

 

Link to comment
Share on other sites

Sorry, but I don't really understand the question.   llSetKeyframedMotion is used to move the whole object.  Calling it from a child prim won't work.  So that's one thing that's going wrong -- your llSetKeyframadeMotion call isn't doing anything.

So, since it's not doing anything, let's look at the rest.   I think the problem is that PRIM_ROTATION is broken in child prims.  This is a an ancient bug that will never be fixed because scripters have long used a work-round, which would itself be broken by a fix.   See the jira SVC-93 for details and a work-around.   However, I think that if I am correct in thinking that you want the child prim to turn on its own Y axis, regardless of how the root prim is rotated, you need to use something like this:

rotation rot;
default
{
    state_entry()
    {
        rot = llEuler2Rot( <0.0,PI_BY_TWO,0.0>);
    }

    touch_start(integer total_number)
    {
       llSetLinkPrimitiveParamsFast(2,[PRIM_ROT_LOCAL,rot *llList2Rot(llGetLinkPrimitiveParams(2,[PRIM_ROT_LOCAL]),0)]);
       rot = ZERO_ROTATION/rot;//invert the rotation
    }
}

That doesn't solve the problem of moving the fish up and down, of course.  I think you need to use PRIM_POSITION in the llSetLinkPPFast call and see what that looks like.  But I hope this helps you get some way forward with the project.

Link to comment
Share on other sites

thank u Innula ... again!

so... i have not yet tried ur solution...will be doing so in a bit.....

and my KFM and rotation stuff is all in the root prim.....the child prim only has a an animator script that animates gif images

here is a psuedo-code for my code:

state entry: targetomega: rotate fish around the root

touch start:

stop targetomega

set child rotation to 0,0,0

set child rotation to 0,pi_by_two,0

kfm

set child rotation to 0,0,0

targetomega ... start rotating the fish again

and the program is getting executed like this:

code before kfm works fine

the rotation line that is just after the kfm seems to be executed simultaneously with the kfm! 

targetomega is executed once the kfm is complete.

below is the code:

if (mtouch==0) {
            llSay(0, "Ama learnt how to jump!");
            llSetRot(llEuler2Rot(<0,0,0>*DEG_TO_RAD));
            rot = llEuler2Rot( <0.0,0.0,0.0>);
            llSetLinkPrimitiveParams(2, [ PRIM_ROTATION, rot ]);
            //llSleep(5);
            rot = llEuler2Rot( <0.0,PI_BY_TWO,0.0>);
            llSetLinkPrimitiveParams(2, [ PRIM_ROTATION, rot ]);
            //llSleep(5);
            llSetKeyframedMotion([<0.0, 0.0, 5.0>, llEuler2Rot(<0, 0, 0> * DEG_TO_RAD), 5,
                <0.0, 0.0, 0.0>, llEuler2Rot(<-180, 0, 0> * DEG_TO_RAD), 5,
                <0.0, 0.0, -5.0>, llEuler2Rot(<0, 0, 0> * DEG_TO_RAD), 5],
                [KFM_MODE, KFM_FORWARD]);
            
            rot = llEuler2Rot( <0.0,0,0>);
            llSetLinkPrimitiveParams(2, [ PRIM_ROTATION, rot ]);
            llSetRot(llEuler2Rot(<0,0,0>*DEG_TO_RAD));

            llTargetOmega(<0,0,1>,1.0,.2);
            mtouch=1;
 

Edited by mansoor50
Link to comment
Share on other sites

There are two separate issues here.

First, llSetKeyframedMotion can't be used on a child prim.  It has to apply to the whole linkset.   What happens if you call it from a child prm I do not know, because I've never tried it, since I know it won't work.    That's not a bug.  That's the way the function is designed.

Second, there is a completely separate bug with llSetPrimitiveParams and associated functions that affects PRIM_ROTATION (but not PRIM_ROT_LOCAL) as applied to child prims.   That you can read about if you look at the jira link I posted above -- basically, the formula the server uses to calculate the rotation contains a mathematical error, which the script must correct for).  So I am not surprised when llSetLinkPrimitiveParams(n, [PRIM_ROTATION]) seems to behave unexpectedly because I know about this bug.  

However, based on your description of what you're trying to do, (turn the child prim on its own y axis) I think you need to use not PRIM_ROTATION but PRIM_ROT_LOCAL in the way I showed you in the previous example.  I may have misunderstood the angle through which you want to turn it, but I think you should be using the method I show you there.

This doesn't help with the problem of moving the fish's position (making it jump out of the water and then back in again) but let's concentrate on one issue at a time.

Get rid of the llSetKeyframedMotion call -- that's not going to work.  Concentrate on the rotation, and we can worry about the positioning later.

Link to comment
Share on other sites

Could you please send me a copy of the object, in world?  Either I'm badly misunderstanding you, or llSetKeyframedMotion is behaving very unexpectedly. 

The wiki says that, 

Quote

This function can only be called on the root prim of a linkset.

and that's also my experience of it.   I also seem to recall that llTargetOmega doesn;'t work while llSetKFM is playing, and I suspect I may be misunderstanding what you're sayig.

 

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 2481 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...