Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //(c)2018 Denise. Virtual Kitten
- // if you use this code please leave it unchanged do not sell or make any product relying on this code.
- float GetBoundaryUsingCastRay(string raytype, float width){
- list ray=[];
- if(raytype=="-y") { ray = llCastRay(llGetPos()+<-(width/2),0.0,0.0>,llGetPos() + <width/2, -50.0, 0.0>,[RC_MAX_HITS, 5]);
- } else if(raytype=="-x") { ray = llCastRay(llGetPos()+<0.0,-(width/2),0.0>, llGetPos() + <-50.0, (width/2), 0.0>,[RC_MAX_HITS, 5]);
- } else if(raytype=="x") { ray = llCastRay(llGetPos()+<0.0,-(width/2),0.0>, llGetPos() + <50.0,(width/2), 0.0>,[RC_MAX_HITS, 5]);
- } else if(raytype=="y") { ray = llCastRay(llGetPos()+<-(width/2),0.0,0.0>, llGetPos() + <(width/2), 50.0, 0.0>,[RC_MAX_HITS, 5]);
- } else return -1;
- // We have a Ray
- llOwnerSay((string)ray + " raytype = " + raytype);
- vector mypos = llGetPos();
- integer i=0;
- float pos =566666;
- integer position;
- mypos = llGetPos();
- do {
- key lkID = llList2Key(ray, i);
- vector pos = llList2Vector(ray,i+1);
- // llOwnerSay("position " + (string)pos+ " i = " +(string)(i+1));
- if(llSubStringIndex(raytype, "x")!=-1) {
- if((integer)pos.x != (integer)mypos.x ) {
- // llOwnerSay(">>position " + (string)pos+ " i = " +(string)(i+1));
- position= i+1;
- i = llGetListLength(ray) - 1;
- };
- } else if(llSubStringIndex(raytype, "y")!=-1) {
- if((integer)pos.y != (integer)mypos.y ) {
- // llOwnerSay(">>position " + (string)pos+ " i = " +(string)(i+1));
- position= i+1;
- i = llGetListLength(ray) - 1;
- };
- }
- i+=2;
- } while(i<=llGetListLength(ray) - 1);
- vector collision_pos = llList2Vector(ray,position);
- // llOwnerSay("Position on x" + (string)collision_pos.x);
- if(llSubStringIndex(raytype, "-y")!=-1 ){ return (integer)llFabs((mypos.y - collision_pos.y));
- } else if(llSubStringIndex(raytype, "-x")!=-1) { return (integer)llFabs((mypos.x-collision_pos.x));
- } else if(llSubStringIndex(raytype, "x")!=-1) {return (integer)llFabs((collision_pos.x-mypos.x ));
- } else if(llSubStringIndex(raytype, "y")!=-1) { return (integer)llFabs((collision_pos.y -mypos.y));
- } else return -1;
- }
- default
- {
- state_entry()
- {
- llVolumeDetect(TRUE);
- // get boundaries
- float boundaryonposy = 0;//GetBoundaryUsingCastRay("y", 0);
- float boundaryonnegy = 0;//GetBoundaryUsingCastRay("-y",0);
- float boundaryonposx = GetBoundaryUsingCastRay("x",0); // ******** Only detect on x acess for a collision
- float boundaryonnegx = 0;//GetBoundaryUsingCastRay("-x",0);
- llOwnerSay(
- "Boundary marker on +x is: "+(string)boundaryonposx +
- " Boundary marker on -x is: "+(string)boundaryonnegx +
- " \nBoundary marker on y is: "+(string)boundaryonposy +
- " Boundary marker on -y is: "+(string)boundaryonnegy);
- }
- collision_start(integer num) // depends on state_entry llVolumeDetect(TRUE);
- {
- key p_collision =llDetectedKey(0);
- llOwnerSay("Collided");
- integer vBitType = llDetectedType(0);
- if (!(vBitType & AGENT || vBitType & AGENT_BY_LEGACY_NAME)) {
- integer l = llDetectedLinkNumber(0);
- vector vAviPos = llDetectedPos(0);
- vector vAviVel = llDetectedVel(0);
- vector vObjPos = llList2Vector(llGetLinkPrimitiveParams(l,[PRIM_POSITION]),0);
- vector vAviToObj = vObjPos - vAviPos;
- vector vAviToObjNorm = llVecNorm(<vAviToObj.x, vAviToObj.y, 0.0>);
- // Rotation vRotAxis = vAviToObjNorm *llEuler2Rot(<0, 0, PI_BY_TWO>);
- }
- }
- touch_start(integer total_number)
- {
- llSay(0, "Touched.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement