Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Making a physical object face me.

Sander Snoodle
Registered User
Join date: 3 Aug 2008
Posts: 8
08-12-2008 05:58
Hi, i wan't to make an object, which is physical, face the owner of itself... however, all rotation scripts, seems to not work, when the object is physical, i have so far tried:
llLookAt
llRotLookAt
llSetParams([PARAMS_ROT,<Something :P>])
However... all theses functions work perfect, when the object is not physical... but doesn't work at all, when it is... I have also tried to change it to non physical for a short duration, to make it face it's owner, and then physical again, however, that one of a second, makes it fall realy awkward all the time.

So: Is there a way, to change the rotation, or make it face an avatar, while it's physical?
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
08-12-2008 06:25
Make sure your object can rotate:
llSetStatus( STATUS_ROTATE_X | STATUS_ROTATE_Y | STATUS_ROTATE_Z, TRUE);
Then try again:)
_____________________
From Studio Dora
Sander Snoodle
Registered User
Join date: 3 Aug 2008
Posts: 8
...
08-12-2008 08:13
Well.. the problem is then he bumps around, he has STATUS_ROTATE_Z to true, the rest id false... But the problem is, at the scripting portal, it says that the previous commands, does not work with physics on, so even though i had them all to true, it still wouldn't work...
Dekka Raymaker
thinking very hard
Join date: 4 Feb 2007
Posts: 3,898
08-12-2008 08:27
doesn't/wouldn't a follower script work in this case?
_____________________
Sander Snoodle
Registered User
Join date: 3 Aug 2008
Posts: 8
08-12-2008 08:39
No, that will make him follow u, not look at u :P
Dekka Raymaker
thinking very hard
Join date: 4 Feb 2007
Posts: 3,898
08-12-2008 08:52
errr just the 'eye' follow script, not the whole bloody thing :)

I made a robot whose eyes follow the nearest avatar around the room, the main body of the robot is static, you could script it to follow owner only, I just thought it 'might' be a work around.
_____________________
Sander Snoodle
Registered User
Join date: 3 Aug 2008
Posts: 8
08-12-2008 09:26
Well... i know i'm asking a lot, but i would prefer the Body to face it as well :P But u might be on to something, so i'll see what i can do :P Thx for the help :P
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
08-12-2008 10:00
From: Sander Snoodle
Well.. the problem is then he bumps around, he has STATUS_ROTATE_Z to true, the rest id false... But the problem is, at the scripting portal, it says that the previous commands, does not work with physics on, so even though i had them all to true, it still wouldn't work...

???
According to: http://www.lslwiki.net/lslwiki/wakka.php?wakka=llRotLookAt
it will work for physical and non physiscal
_____________________
From Studio Dora
Sander Snoodle
Registered User
Join date: 3 Aug 2008
Posts: 8
08-12-2008 10:59
Well... i don't think so... if i put phusics off... it works just perfectly, if i put it on, it doesn't work at all... in addition, the site doesn't seem to have been updated in a while, no axamples or nothing :S
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
08-12-2008 11:15
If you honestly want help in this forum you need to provide more information. It would be a fantastic help if you could let us look at your script..
So far you have told us that you can not turn or rotate an object! You want us to believe that is true, when we do it every day? get serious :(
_____________________
From Studio Dora
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
08-12-2008 11:37
This script is working fine for me with both a physical and non-physical object. You might also want a llSetBuoyancy() and/or a llMoveToTarget() of some sort to keep the object floating in position so it can freely rotate if it is physical.

This script has been compiled and tested. However, it assumes that the object's coordinate system is setup in the standard x-forward, y-left, z-up orientation.

CODE

float UPDATE_PERIOD = 0.5;

integer STAY_LEVEL = FALSE;
float ROT_STRENGTH = 0.5;
float ROT_TAU = 0.5;

faceOwner()
{
list ownerDetails = llGetObjectDetails(llGetOwner(), [ OBJECT_POS ]);
if (llGetListLength(ownerDetails) < 1)
{
return;
}

vector ownerPos = llList2Vector(ownerDetails, 0);

vector currPos = llGetPos();
vector ownerDir = llVecNorm(ownerPos-currPos);

vector newX;
vector newY;
if (STAY_LEVEL)
{
if (1.0-llFabs(ownerDir.z) < 0.01)
{
return;
}

newY = llVecNorm(<-ownerDir.y, ownerDir.x, 0.0>); // z % ownerDir
newX = <newY.y, -newY.x, 0.0>; // newY % z
} else
{
newX = ownerDir;

if (1.0-llFabs(ownerDir.z) < 0.01)
{
rotation currRot = llGetRot();
vector currY = llRot2Fwd(currRot);

if (1.0-llFabs(currY.z) < 0.01)
{
vector currX = llRot2Fwd(currRot);
newY = llVecNorm(<-currX.y, currX.x, 0.0>); // z % currX
} else
{
newY = llVecNorm(<currY.x, currY.y, 0.0>);
}
} else
{
newY = llVecNorm(<-newX.y, newX.x, 0.0>); // z % newX
}
}

rotation newRot = llAxes2Rot(newX, newY, newX%newY);

llRotLookAt(newRot, ROT_STRENGTH, ROT_TAU);
}

default
{
state_entry()
{
llSetTimerEvent(UPDATE_PERIOD);
}

timer()
{
faceOwner();
}
}
Sander Snoodle
Registered User
Join date: 3 Aug 2008
Posts: 8
The Script
08-12-2008 15:21
*aight guys, sry about not being more specific, but i haven't been on SL for more than a week, so i'm very new to this... so here's the code:

integer Define=0;
integer Doing=0;
float Hunger=100;
integer GoingForFood=0;
default
{
state_entry()
{
llSetStatus(STATUS_ROTATE_X | STATUS_ROTATE_Y, FALSE);
llSetStatus(STATUS_PHYSICS, TRUE);
llSensorRepeat("",llGetOwner(),AGENT,1000,PI,0.15);
llListen(3,"",llGetOwner(),"";);
llSetTimerEvent(2);
}
timer()
{
Hunger-=1;
}
touch(integer Toucher)
{
llSay(0,"I'm "+(string)Hunger+" hungry...";);
}
sensor(integer Number)
{
Doing+=1;
if (Doing!=0 & GoingForFood==0)
{
vector position=llDetectedPos(0);
vector Offset=<-1,0,-3>;
position+=Offset;
llSetStatus(STATUS_PHYSICS, TRUE);
llMoveToTarget(position,0.4);
vector MyPos=llGetPos();
vector OwnPos=llDetectedPos(0);
float A=llAbs((integer)MyPos.x-(integer)OwnPos.x);
float B=llAbs((integer)MyPos.y-(integer)OwnPos.y);
float C=A*A+B*B;
if (B==0)
B=0.01;
if (C==0)
C=0.01;
float Dir=llSin(B/C);
llRotLookAt(<0,0,50,0>,0.5,0.5);
}
else
{
if (llDetectedOwner(0)==llGetOwner())
{
vector position=llDetectedPos(0);
llMoveToTarget(position,0.4);
GoingForFood=1;
}
}
if (Doing==5)
{
llSensorRepeat("Simple Pet Food","",PASSIVE,1000,PI,0.15);
}
else
llSensorRepeat("",llGetOwner(),AGENT,1000,PI,0.15);

}
listen(integer Channel, string Name, key Key, string Mess)
{
if (Define==0)
{
if (Mess=="PetSetMetallic On";)
{
llSetPrimitiveParams([PRIM_BUMP_SHINY,ALL_SIDES,PRIM_SHINY_HIGH,PRIM_BUMP_NONE]);
}
if (Mess=="PetSetMetallic Off";)
{
llSetPrimitiveParams([PRIM_BUMP_SHINY,ALL_SIDES,PRIM_SHINY_NONE,PRIM_BUMP_NONE]);
}
if (Mess=="PetSetGender Boy";)
{
llMessageLinked(LINK_ALL_OTHERS,45,"","";);
}
if (Mess=="PetSetGender Girl";)
{
llMessageLinked(LINK_ALL_OTHERS,46,"","";);
}
if (Mess=="PetSetColorR";)
{
Define=1;
}
if (Mess=="PetSetColorG";)
{
Define=2;
}
if (Mess=="PetSetColorB";)
{
Define=3;
}
if (Mess=="PetSetColor Red";)
{
llSetColor(<1,0,0>,ALL_SIDES);
}
if (Mess=="PetSetColor Red";)
{
llSetColor(<1,0,0>,ALL_SIDES);
}
if (Mess=="PetSetColor Blue";)
{
llSetColor(<0,0,1>,ALL_SIDES);
}
if (Mess=="PetSetColor Green";)
{
llSetColor(<0,1,0>,ALL_SIDES);
}
if (Mess=="PetSetColor Black";)
{
llSetColor(<0,0,0>,ALL_SIDES);
}
if (Mess=="PetSetColor White";)
{
llSetColor(<1,1,1>,ALL_SIDES);
}
if (Mess=="PetSetColor Yellow";)
{
llSetColor(<1,1,0>,ALL_SIDES);
}
if (Mess=="PetSetColor Orange";)
{
llSetColor(<1,0.5,0>,ALL_SIDES);
}
if (Mess=="PetSetColor LightBlue";)
{
llSetColor(<0.5,1,1>,ALL_SIDES);
}
if (Mess=="PetSetColor Purple";)
{
llSetColor(<0.56862745098039215686274509803922,0,1>,ALL_SIDES);
}
if (Mess=="PetSetColor Brown";)
{
llSetColor(<1,0.25,0>,ALL_SIDES);
}
if (Mess=="PetSetColor Pink";)
{
llSetColor(<1,0.35294117647058823529411764705882,1>,ALL_SIDES);
}
if (Mess=="PetSetColor LightGreen";)
{
llSetColor(<0,1,0.5>,ALL_SIDES);
}
if (Mess=="PetSetColor Gray";)
{
llSetColor(<0.74901960784313725490196078431373,0.74901960784313725490196078431373,0.74901960784313725490196078431373>,ALL_SIDES);
}
if (Mess=="PetSetColor Crimson";)
{
llSetColor(<0.5,0,0>,ALL_SIDES);
}
if (Mess=="PetSetColor Navy";)
{
llSetColor(<0,0.5,0.5>,ALL_SIDES);
}
}
else
{
vector Color=llGetColor(ALL_SIDES);
float RR=Color.x;
float BB=Color.z;
float GG=Color.y;
if (Define==1)
{
llSetColor(<;(float)Mess,GG,BB>,ALL_SIDES);
Define=0;
}
if (Define==2)
{
llSetColor(<RR,(float)Mess,BB>,ALL_SIDES);
Define=0;
}
if (Define==3)
{
llSetColor(<RR,GG,(float)Mess>,ALL_SIDES);
Define=0;
}
}
if (Channel==3)
{
llSay(0,Mess);
}
}
}

ps. i haven't tried the script that was kindly provided to me, since it is late, i will do it first thing in the morning though :P
Sander Snoodle
Registered User
Join date: 3 Aug 2008
Posts: 8
Other Info
08-12-2008 15:25
Well... in other information, i cuold tell u that this is a pet i'm working on, that should be able to follow u, but also look at u...
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
08-13-2008 02:13
Great! You certainly have been programming for more than a week:)
The only place I see a rotation of a kind is in this line:
llRotLookAt(<0,0,50,0>,0.5,0.5);
The first argument is not right, each part must be a number in the range: [-1;1] It is a 'quaternion' and does not take degrees nor radians as arguments. LSL has functions to convert between Euler rotations and quaternions.
Read more about rotations and quaternions here: http://www.lslwiki.net/lslwiki/wakka.php?wakka=rotation

I have not tried to overlook the logic in all of the program but it caught my eye that you have a set distance=1000 in the llSensoRepeat(). That distance will not go higher than 96.0 meters
_____________________
From Studio Dora
Sander Snoodle
Registered User
Join date: 3 Aug 2008
Posts: 8
08-13-2008 04:33
I have tried to narrow the script down to this (To make it easier to get an overview :P):

integer Define=0;
integer Doing=0;
float Hunger=100;
integer GoingForFood=0;
default
{
state_entry()
{
llSetStatus(STATUS_ROTATE_X | STATUS_ROTATE_Y, TRUE);
llSetStatus(STATUS_PHYSICS, TRUE);
llSensorRepeat("",llGetOwner(),AGENT,1000,PI,0.15);
}
sensor(integer Number)
{
vector position=llDetectedPos(0);
vector Offset=<-1,0,-3>;
position+=Offset;
llSetStatus(STATUS_PHYSICS, TRUE);
llMoveToTarget(position,0.4);
vector MyPos=llGetPos();
vector OwnPos=llDetectedPos(0);
float A=llAbs((integer)MyPos.x-(integer)OwnPos.x);
float B=llAbs((integer)MyPos.y-(integer)OwnPos.y);
float C=A*A+B*B;
if (B==0)
B=0.01;
if (C==0)
C=0.01;
float Dir=llSin(B/C);
rotation quat=llEuler2Rot(<0,0,350>;);
llRotLookAt(quat,0.5,0.5);

}
}

And it still doesn't work :S
It does, though, the instant i set Physics to false...
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
08-13-2008 08:06
This script works:
CODE
default
{
state_entry()
{
llSetStatus(STATUS_ROTATE_X | STATUS_ROTATE_Y | STATUS_ROTATE_Z, TRUE);
llSetStatus(STATUS_PHYSICS, TRUE);
llSensorRepeat("",llGetOwner(),AGENT,96.0,PI,1.0);
}
sensor(integer Number)
{
vector position=llDetectedPos(0);
vector Offset=< -1.0, 0.0, 1.5>;
position+=Offset;
llSetStatus(STATUS_PHYSICS, TRUE);
llMoveToTarget(position,0.4);
llLookAt(llDetectedPos(0)+<0.0, 0.0, 1.0>,0.5,0.5);
}
}

It was made by cutting heavily in your code.
Avoid using angles, SIN, COS and TAN whenever you can.
In general: Keep it simple:)
_____________________
From Studio Dora
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
09-18-2008 12:40
also you can add llDetectedPos(0) if you want it to keep it's position relative to which way the owner is facing
From: Dora Gustafson
This script works:
CODE
default
{
state_entry()
{
llSetStatus(STATUS_ROTATE_X | STATUS_ROTATE_Y | STATUS_ROTATE_Z, TRUE);
llSetStatus(STATUS_PHYSICS, TRUE);
llSensorRepeat("",llGetOwner(),AGENT,96.0,PI,1.0);
}
sensor(integer Number)
{
vector position=llDetectedPos(0);
vector Offset=< -1.0, 0.0, 1.5>;
position+=Offset*llDetectedRot();
llSetStatus(STATUS_PHYSICS, TRUE);
llMoveToTarget(position,0.4);
llLookAt(llDetectedPos(0)+<0.0, 0.0, 1.0>,0.5,0.5);
}
}

It was made by cutting heavily in your code.
Avoid using angles, SIN, COS and TAN whenever you can.
In general: Keep it simple:)
_____________________
Dark Heart Emporium

http://www.xstreetsl.com/modules.php?name=Marketplace&MerchantID=133020

want more layers for tattoos, specifically for the head? vote here
http://jira.secondlife.com/browse/VWR-1449?

llDetectedCollision* Functions similar to touch
http://jira.secondlife.com/browse/SVC-3369