Jump to content

Using llSetPrimitiveParams to point a flexi prim at an avatar


kayra Rae
 Share

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

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

Recommended Posts

Hi all! :)

I'm trying to create a flexi prim that will "point" at the closest avatar to it. I've seen this before and have decided to try it for mysely.

At first I tried llLookAt. This works well for pointing, but ends up "uprooting" the flexi prim and rotating it like a weather vane. I need the flexi prim to stay "grounded" to what it's attached to, and simply "lean" towards the avatar.

So, llSetPrimitiveParams seems like the only route, using the 'force' vector to "push" the top of the flexi prim towards the target.

I did some experiments using the "force" vector and found that I can point the flexi by varying the x and y components of the "force" parameter to llSetPrimitiveParams. Here's a simple example for cardinal directions:

 

PointFlexi( string dir ) {
    // point the tail at p, which is either a person or cardinal direction.
    vector pointdir;
   
    if( dir == "west" ) {
    	llOwnerSay( "Pointing west" );
        pointdir = <10, 0, 0>;
    }
    else if( dir == "north" ) {
    	llOwnerSay( "Pointing north" );
        pointdir = <0, 10, 0>;
    }
    else if( dir == "east" ) {
        llOwnerSay( "Pointing east" );
        pointdir = <-10, 0, 0>;
    }
    else if( dir = "south" ) {
        llOwnerSay( "Pointing south" );
        pointdir = <0, -10, 0>;
    }

    llSetPrimitiveParams( [ PRIM_FLEXIBLE, 1, 3, 0.3, 0.6, 0.0, 1.0, pointdir] );
}

 

 

The problem I can't wrap my head around is how best to translate an object or avatar's location into a "force" value I can apply to my flexi prim in order to point it.

So far what I've come up with is that I can run llSensorRepeat() and get an llDetectedPos() and my llGetPos(), then I'd need to conjure some math to get a directional vector between the two objects, then somehow translate that angle to the force value I need for llSetPrimitiveParams(). Gah!! :P

Can anyone shed some light on this for me? I'd be soooo grateful!

Thanks!

Link to comment
Share on other sites

A couple of thoughts:

First, you don't need to use a repeating sensor, since you already know who your target is after first contact.  Just use vector Where = llList2Vector(llGetObjectDetails(av_UUID,[OBJECT_POS]),0) in a timer.

Then, you can rotate your object to look at Where with

llSetRot(llRotBetween( <1.0,0.0,0.0>, llVecNorm(llGetPos() - Where) ) );

I can't get in world at the moment to test it, but I think that's right. 

 

Link to comment
Share on other sites

You need no angle to find directions
Find the vector from one point to the other:

vector V = llDetectedPos(0)-llGetPos();

 now V.x is the East component and V.y is the North component
That of course is only useful when your flexi prim is not rotated ( or maybe it doesn't matter)

You may want to multiply with a constant to make the effect smaller or larger
I do not recall if the prim bend with the force or not. If you get the wrong direction multiply by minus one

:smileysurprised::):smileyvery-happy:

 Addition, working script for reference:

// flexible point at by force, script by Dora Gustafson, Studio Dora 2013

list flexding;

default
{
    state_entry()
    {
        flexding = llGetPrimitiveParams( [PRIM_FLEXIBLE]);
    }
    touch_end( integer num )
    {
        vector Point = llVecNorm( llList2Vector( llGetObjectDetails( llDetectedKey(0), [OBJECT_POS]), 0)-llGetPos());
        llSetPrimitiveParams( [PRIM_FLEXIBLE]+llList2List( flexding, 0, -2)+[Point]);
        llSetTimerEvent( 5.0 );
    }
    timer()
    {
        llSetPrimitiveParams( [PRIM_FLEXIBLE]+flexding);
        llSetTimerEvent( 0.0 );
    }
}

 

 

Link to comment
Share on other sites

Interesting : the point should be normalized ( if i understand you , the magnitude has no importance ) .

But in the build tools of the flexi prim , we can set the vector , but it s not normalized .

 

Probably it explains the confusions happened and the difficulties to undertand how work the flexis

Link to comment
Share on other sites

The magnitude is important, the force is proportional to the magnitude
The flexi prim bend more with a bigger force
The reason I normalize the vector in the reference script, is that I don't want the force to increase with the distance between person and object

:smileysurprised::):smileyvery-happy:

Link to comment
Share on other sites

  • 2 weeks later...

Thank you SO MUCH, Dora!!!

This is exactly what I was looking for! :)))

I'm curious about the local orientation, however.

This is for a tail, which is attached to me, and i can be facing any direction, and the prim of course has it's own positioning while attached.

So my guess is i'll have to take that into consideration.

I've seen a method that derives a global orientation from a local one. Would I need to convert first the orientation of the prim before I apply the x and y vector components to the prim? Or would I calculate this delta and apply it to the values I pass to llSetPrimitiveParams?

Link to comment
Share on other sites

I wouldn't worry about local coordinates at all
The flexi force is global and the vector from your tail to the target is the direction of the force

I also would include all three coordinates: x, y and z as I do in the reference script
I see no reason to exclude z.

:smileysurprised::):smileyvery-happy:

Link to comment
Share on other sites

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