Search the Community
Showing results for tags 'raycast'.
-
Hello, The title pretty much says it all. I have been looking for years, for a competent, willing scripter that can create a boxing system for me. I run a boxing league in world and REALLY want my own system created. If anyone out there is willing to take on this job, please reply here, or contact me in world @ Brandon Ghost. Thank you! - Brandon
-
Hello. My use case: Have a project idea that would benefit of a detailed llCastArray() friendly surface. Which i think is a physic shape, but the down side is un-necessary load on the server as it can be complex or many small ones that will add up, when its only purpose is to be invisible and an be an recipient surface llCastArray(). So my question is: Can a physic shape be made server friendly in the sense of a medium/high vertex count ?
-
i think i figured out what i'm doing wrong. i am trying to calculate the angle of a slope between two points. point 1 = the spot directly below the avatar where it is standing. (in region coordinates) point 2 = the spot the ray intersects the ground ahead of the avatar. (in region coordinates, translated from the avatar's local forward axis) and i have this formula: angle = RAD_TO_DEG*( llAtan2( (p2.z - p1.z),(p2.x - p1.x) )); i THINK the problem is, that i'm just using the X and Z coordinates, and not correcting for the Y coordinate, if the avatar is not facing along the global X axis. so i found this: https://www.euclideanspace.com/maths/geometry/elements/projections/index.htm how to project a point (my target hit with x,y coordinates) onto a line (the global x axis). um... okay, so i have to take the line that is the avatar's facing, project a line at a right angle to that line from the point, and find out where it hits the X axis. uh... yeah, i dunno how to do that :/ except by drawing on graph paper! :X drawing: https://prnt.sc/onjtdl okay, i worked THIS out: http://prntscr.com/onk6ao if i can just get the x/y plane distance of a, then calculate the x/y coordinate of 2a along the avatar facing... THAT x coordinate should be the one i need. and i don't need to mess around with all those pythagorean thingies. what's the 2d version of llVecDist? oh, set the Zs to 0 first... okay, i came up with this, and it returns total BS. it even returns different answers if i click it (activate the calculation by touch) multiple times, without moving in between. float getSlope() { float ht = 0.75; //--normally a calculated global. vector pos = llGetPos(); //--we know where the floor is, cuz we're standing on it @ -ht. vector target = pos; rotation rot = llGetRot(); target = pos + <3.*ht,0.,0.> *rot;//-- test 3 ahead and 2.5 down target.z = target.z - 2.5*ht; // llOwnerSay("Aiming "+(string)pos+" to "+(string)target); list res2 = llCastRay(pos, target, [RC_REJECT_TYPES, RC_REJECT_AGENTS | RC_REJECT_PHYSICAL, //RC_DATA_FLAGS, RC_GET_NORMAL, RC_MAX_HITS, 1]); llOwnerSay("RC returned:"+llDumpList2String(res2, ",")); float angle; if(llList2Integer(res2, -1) != 0) { vector p1 = pos; vector p2 = llList2Vector(res2, 1); //--calculate X without Y vector xy1 = p1; vector xy2 = p2; xy1.z = 0.0; //--get rid of Z influence xy2.z = 0.0; float dist = llVecDist(xy1,xy2); vector xTarget = pos + <2*dist, 0., 0.> * rot; //--SLOPE: p1.z -= ht; //--make this the floor p1.x = xTarget.x; //--make this our actual distance along avatar FWD angle = RAD_TO_DEG*( llAtan2( (p2.z - p1.z),(p2.x - p1.x) )); } else //--we didn't hit anything, the slope is WAY down. angle = -45.0; //--midway to down. fudged. if(angle > 90.0) angle -= 180.0; else if (angle < -90.0) angle += 180.0; return angle; } and no, i don't know how to do angle math, either :X
-
so on my slope quest... i have two coordinates, one that is right below my avatar, and one that is about 2 meters ahead of it. these are raycast coordinates, shooting out from the avatar's center point. anyway, i have gotten the formula that the angle of the slope is Tan^-1 (slope). and slope = (z2 - z1)/ (x2 - x1). vector p1 = llList2Vector(res1, 1); vector p2 = llList2Vector(res2, 1); float angle = llPow(llTan( (p2.z - p1.z)/(p2.x - p1.x) ), -1); so tangent of the slope to the -1 power. i'm standing on a prim rotated at 45 degrees, and facing upslope. but the angle keeps coming out to tiny numbers like -0.41267. eh??? my brain is melted. https://www.quora.com/How-can-you-find-the-angle-of-line-by-using-its-slope if you're nuts, these are some of the readouts i got: yeah, i tried getting the normals, but... i don't think i can wrangle those into anything useful for my purposes. i'm trying to see if the avatar is walking up or down a slope, and how steep it is. the normal just gives me the angle of the prim surface, not any idea of which way im facing on it.
-
i know i know how to do this... sorta. but i can't seem to figure it out. okay, i'm trying to ray cast from an attachment, and i want to get the spot straight down from the center of my avatar (easy, thats llGetPos and lower the z coordinate), and "ahead" of my avatar. which i know is local pos + x, BUT... to get that in region coordinates, compared to which way my avatar is facing, i need to use (i think??) Rot2Fwd. i'm just... not sure where/how? vector fwd = llRot2Fwd( llGetLocalRot() ); vector targetPos = llGetPos() + (fwd* ht); this is from the example on the wiki page... http://wiki.secondlife.com/wiki/LlRot2Fwd it says 'to move an object 5 meters on its forward axis.' in this case i'm moving it "ht" meters on its X axis. or... not MOVING it, but getting a coordinate that is supposed to be ht meters ahead of where i am. but when i face the Y axis... i'm not getting a change in the Y axis calculation? :/ no. i changed 'ht' to 10 meters, but only the x coordinate is ever changing. it's been a long day...
- 7 replies
-
- raycast
- coordinates
-
(and 1 more)
Tagged with:
-
This script is intended to help show exactly where the ray travels and what it hits, if anything. All you need to do is manually adjust the visualizer's position and rotation using the build tools, and touch the object to "fire" a ray. The length of the ray can be adjusted by saying any length in local chat, and the visualizer will adjust to it. To get set up, rez 3 (of any) prims, link them together, and then put this script in. It will create an object like this: And here it is in action, hitting the inside of a hollow sphere: Here's the code: float length = 5; default { state_entry() { // This simply sets up the object properly. // Link 1 and 3 are spheres, link 2 is the long cylinder. llSetLinkPrimitiveParamsFast(1,[ 9, 3, 0, <0,1,0>, 0.0, <0,0,0>, <0,1,0>, 18, -1, <0.251,0,1>, 0.5, 7, <0.2,0.2,0.2>, 34, 2, 33, <0,0,0>, 9, 1, 0, <0,1,0>, 0.0, <0,0,0>, <1,1,0>, <0,0,0>, 18, -1, <1,0,0.251>, 1, 7, <0.01,0.01,10>, 35, <0.4950,1,0>, 30, 1, 34, 3, 33, <0,0,0>, 9, 3, 0, <0,1,0>, 0.15, <0,0,0>, <0,1,0>, 18, -1, <0.251,0,1>, 0.5, 7, <0.2,0.2,0.2>, 30, 1 ]); // Only listen to the owner's avatar. llListen(0, "", llGetOwner(), ""); } listen(integer c, string n, key id, string m) { // Only react to valid floats. if( ((float)(m+"1") == 0.0) ) return; length = (float)m; llSetLinkPrimitiveParamsFast(2, [PRIM_SIZE, <0,0,length*2>]); llOwnerSay("New length set."); } touch_start(integer n) { // Rotate the end-position of the ray with the object. list data = llCastRay( llGetPos(), llGetPos() + ((<0,0,length>) * llGetRot()), [RC_DATA_FLAGS, RC_GET_ROOT_KEY | RC_GET_LINK_NUM]); if(llList2Integer(data, -1)) // Was there a hit? { llOwnerSay("Raycast hit \"" + llKey2Name(llList2Key(data, 0)) + "\" link #" + llList2String(data, 1)); // "Dividing" the position with the object's own rotation removes the rotation. llSetLinkPrimitiveParamsFast(3, [PRIM_POS_LOCAL, (llList2Vector(data, 2) - llGetPos()) / llGetRot()]); } else { llOwnerSay("Nothing was hit."); llSetLinkPrimitiveParamsFast(3, [PRIM_POS_LOCAL, <0,0,length>]); } } }