current issues:
**climbing speed is very fast (about 10m/s) no matter how strong an impulse/push I use.
**sometimes the avatar will just stop climbing for no apparent reason (even though it's still colliding) and begin to "Fall" while floating.
thought process:
*You avatar is walking along and it runs into something (oh noes).
*The "something" turns out to be in front of you, and you are lower than it's lower edge so lets climb up by pushing (applying an impulse) upwards.
*You're still colliding with something, but it's the "something" you decided to climb, so continue to push upwards (and forwards to continue the collision).
*you stopped colliding with what you wanted to climb so stop pushing upwards
so based off these "simple" assumptions I created, re-created, debugged, trouble shot, commented, and am about to take out back and shoot.... the following script
CODE
integer walking;
vector wallpos;
string direction;
integer infront(vector mypos, vector tarpos)
{
vector mydir=llRot2Fwd(llGetRot());
vector tardir=llVecNorm(tarpos-mypos);
if(llVecMag(mydir + tardir) <1)
{
return FALSE;
}
else
{
return TRUE;
}
}
key wall;
default
{
collision_start(integer num)
{
//llOwnerSay("collided");
vector mypos=llGetPos();
vector tarpos=llDetectedPos(0);
vector wallheight=llList2Vector(llGetBoundingBox(llDetectedKey(0)),0)+tarpos;
if(infront(mypos,tarpos)==TRUE)//we hit something that's infront of us
{
if(mypos.z >= wallheight.z)//We're above the bottom of the wall
{
wall=llDetectedKey(0);
wallpos=tarpos;
llSetBuoyancy(1);//impulse doesn't work that well if we're not "floaty"
llApplyImpulse(llRot2Fwd(llGetRot()),TRUE);
//llSetText("climbing wall: " + (string)wall,<1,1,1>,1);
llSetTimerEvent(.5);//debug display
}
}
}
collision(integer num)
{
if(llDetectedKey(0)==wall)//we're still colliding with the wall we're supposed to be climbing
{
llApplyImpulse(llRot2Fwd(llGetCameraRot())+<0,0,.125>*llGetMass(),TRUE);
//llPushObject(llGetOwner(), <0,0,1>*llGetMass()+llGetVel(), ZERO_VECTOR, TRUE);
}
else//we're not hitting the wall we're supposed to be climbing
{
llSetBuoyancy(0);
//llSetText("",<1,1,1>,0);
}
}
collision_end(integer num)
{
vector mypos=llGetPos();
vector tarpos=llDetectedPos(0);
vector wallheight=llList2Vector(llGetBoundingBox(llDetectedKey(0)),1)+tarpos;
if(wall==llDetectedKey(0))//we stopped colliding with the wall we're supposed to be climbing
{
if(wallheight.z/2+tarpos.z < mypos.z)//we're above the wall we're supposed to be climbing
{
//llApplyImpulse(llRot2Fwd(llGetRot())*2+<0,0,1>*llGetMass(),TRUE);
//llSetText("",<1,1,1>,0);
llSetBuoyancy(0);
}
else//we're still below the wall we're supposed to be climbing
{
llApplyImpulse(llRot2Fwd(llGetCameraRot())+<0,0,1>,TRUE);
}
}
}
timer()//debug display
{
vector walltop=llList2Vector(llGetBoundingBox(wall),1)+wallpos;
vector wallbottom=llList2Vector(llGetBoundingBox(wall),0)+wallpos;
llSetText("Wall Key: " +(string)wall + "\n My Position: " + (string)llGetPos() + "\n Wall's lower edge height: " + (string)wallbottom.z + "\n wall's upper edge height: "+ (string)walltop.z,<1,1,1>,1);
}
}