Jump to content

Rotating a compass object with avatar rotation


NotTooManyItems
 Share

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

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

Recommended Posts

I've got a compass object worn on my avatar and would like it to always be rotated towards a location in world no matter what direction the avatar who wears it is facing.

At the moment the object points in the correct direction but only when the avatar is facing North.

Facing North - https://i.gyazo.com/bbd35b98bd439b2971448a12f1aaeeac.png
Facing South - https://i.gyazo.com/def55de0ad493b0bd7d28b0a35d1a651.png

In both images the arrow continues to point in the same way but the avatar is facing a different direction. I need the arrow to change to continue facing <0,0,0> when the avatar rotates.

Code

vector vTarget = <0,0,0>;
vector vPos = llGetPos(); //object position
float fDistance=llVecDist(<vTarget.x,vTarget.y,0>,<vPos.x,vPos.y,0>); // XY Distance, disregarding height differences.
llSetRot(llRotBetween(<1,0,0>,llVecNorm(<fDistance,0,0>)) * llRotBetween(<1,0,0>,-llVecNorm(<vTarget.x - vPos.x,vTarget.y - vPos.y,0>)));

SOLUTION

vector vTarget = llList2Vector(waypoints, current_waypoint);
rotation vRot = llGetRot();
vector vAvatar = llGetPos();
vector direction = (vTarget - vAvatar) / vRot;
direction.z = 0;
direction = llVecNorm(direction);   
rotation final = llRotBetween(<1,0,0>, -direction);   
llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_ROTATION, final]);

 

Edited by NotTooManyItems
Link to comment
Share on other sites

The most important thing is to negate the avatar's rotation, if you're trying to reference a position in world-coordinates. Otherwise what you have is a relative offset, which means that it will change with the avatar as it rotates.

This can be done by "dividing" the rotation by the avatar's rotation. (It's not really division, that's just the symbol we use for it.)

vector target = <0,0,0>;
vector avatar = llGetPos();

vector direction = target - avatar;
direction.z = 0;
direction = llVecNorm(direction);

rotation final = llRotBetween(<1,0,0>, direction) / llGetRot();

llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_ROTATION, final]);

 

Edited by Wulfie Reanimator
  • Like 1
  • Thanks 1
Link to comment
Share on other sites

12 minutes ago, Qie Niangao said:

Unless I'm confused, I think it may look better if the object is attached to http://wiki.secondlife.com/wiki/ATTACH_AVATAR_CENTER so it doesn't appear to rotate based on the avatar's animations. 

It will still rotate according to the avatar's general direction. When you turn left, Avatar Center turns as well.

Link to comment
Share on other sites

8 hours ago, Wulfie Reanimator said:

The most important thing is to negate the avatar's rotation, if you're trying to reference a position in world-coordinates. Otherwise what you have is a relative offset, which means that it will change with the avatar as it rotates.

This can be done by "dividing" the rotation by the avatar's rotation. (It's not really division, that's just the symbol we use for it.)


vector target = <0,0,0>;
vector avatar = llGetPos();

vector direction = target - avatar;
direction.z = 0;
direction = llVecNorm(direction);

rotation final = llRotBetween(<1,0,0>, direction) / llGetRot();

llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_ROTATION, final]);

 

Thanks! Dividing by llGetRot() did it! And the llSetLinkPrimitiveParamsFast() function made the rotation smoother!

  • Like 1
Link to comment
Share on other sites

On 2/24/2021 at 6:25 PM, Wulfie Reanimator said:

It will still rotate according to the avatar's general direction. When you turn left, Avatar Center turns as well.

On 2/24/2021 at 7:42 PM, Lucia Nightfire said:

Yeah, wearing this on AV Center will encounter the +/- 30 degree turning buffer users have which is responsible for one person seeing you facing one direction and another seeing you facing slightly different than that.

I wonder if I'm just not explaining what I mean. Certainly "when you turn left, Avatar Center turns as well" -- the distinction I was trying to make is that Avatar Center has the advantage of remaining oriented in the same direction as the agent, regardless of how animations move the avatar. Or at least that's been my experience. Here's a simple demonstration:

integer animated;

default
{
    state_entry()
    {
        llSetTimerEvent(1.0);
    }
    run_time_permissions(integer perms)
    {
        if (PERMISSION_TRIGGER_ANIMATION & perms)
            if (animated = !animated)
                llStartAnimation("turn_180");
            else
                llStopAnimation("turn_180");
    }
    touch_start(integer total_number)
    {
        llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);
    }
    timer()
    {
        vector direction = (<0,0,0> - llGetPos()) / llGetRot();
        direction = llVecNorm(<direction.x, direction.y, 0.0>);   
        llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_ROTATION, llRotBetween(<1,0,0>, -direction)]);
    }
}

Drop that in some prim that shows the orientation of its X axis, then attach it to Pelvis and touch it. It will spin around according to the avatar's "turn_180" animation. Touch it again to stop the animation, then try it attached to Avatar Center instead; it should retain the agent's orientation (which will still turn left with the left arrow key, etc).

Link to comment
Share on other sites

Just now, Qie Niangao said:

I wonder if I'm just not explaining what I mean. Certainly "when you turn left, Avatar Center turns as well" -- the distinction I was trying to make is that Avatar Center has the advantage of remaining oriented in the same direction as the agent, regardless of how animations move the avatar.

You're totally correct, but I believe that's what @NotTooManyItems was already doing and that's the assumption I made with the script in my first post.

  • Thanks 1
Link to comment
Share on other sites

On 2/24/2021 at 7:42 PM, Lucia Nightfire said:

Yeah, wearing this on AV Center will encounter the +/- 30 degree turning buffer users have which is responsible for one person seeing you facing one direction and another seeing you facing slightly different than that.

Just for my own curiosity, do the 'AvatarRotateThresholdSlow' and 'AvatarRotateThresholdFast' debug settings have any effect on your avatar's rotation as seen by other viewers?

Edited by Quistessa
Link to comment
Share on other sites

51 minutes ago, Quistessa said:

Just for my own curiosity, do the 'AvatarRotateThresholdSlow' and 'AvatarRotateThresholdFast' debug settings have any effect on your avatar's rotation as seen by other viewers?

i don't think so. Debug settings only apply to our viewer

Link to comment
Share on other sites

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