Talk:LlCastRay
Why isn't this using the sensor API?
- The sensor API already exists and has well understood behavior.
- The sensor API resolves many of the problems people have brought up, such as list length and range.
- The sensor API is asynchronous.
- Creating new APIs when there are already viable existing ones leads to Mainframe-itis.
- This would be an opportunity to add a result filter variant to the llSensor() family...
llCastRay(string name, key id, integer type, float range, vector path, integer request_mask);
Eg:
llCastRay("", "", AGENT|ACTIVE|PASSIVE, 32, <1, 0, 0>, SENSOR_POSITION); /... sensor(integer n) { integer i; for(i = 0; i < n; i++) llSay(0, "Ping at "+(string)llDetectedPos(i)); }
-- Argent Stonecutter 11:53, 7 July 2010 (UTC)
- I think somewhere Falcon said not doing it like sensors was intentional in order to get the data the moment the command is run instead of having to wait for an event, i don't remember seeing an explanation why this was a better approach though.
- Btw, how would the normal of the hit(s) be reported? A new llDetected* function? Perhaps this would be an opportunity to introduce list llDetected(integer index, list what), this way future llDetected* functions can be easily prototyped without needing to actually implement a whole new command in the server (you know, like with the primitive params stuff)
- ps: talking about normals and llDetected* i would like to plug SVC-3369 "llDetectedCollisions* (similar to llDetectedTouch*)" , mind taking a look Falcon?
--TigroSpottystripes Katsu 12:46, 7 July 2010 (UTC)
- This was not done like the sensor API because it's not really all that similar to sensors. Unfortunately I don't have time to get into a discussion of why the API you're suggesting would be problematic, but if you read the history of this feature (SVC-5389), I hope you'll begin to see where I'm coming from.
- Tigro, Sorry, I'm backlogged for a month at this point, so I don't think I'll be able to look at that soon. :) In general, I'm looking at this feature right now only because it affects a huge audience and is way, way overdue. Oh, and because I'm a physics guy and it's a physics feature more than anything else. :P
Falcon Linden 03:34, 8 July 2010 (UTC)
- SVC-5389 is about download problems. Do you mean SVC-5381? There's a couple of notes about sensors being "heavy", but not really any explanation of why they're "heavy". The only heavy feature of sensors is that it calculates and returns more information than you're asking for, and the request_mask would take care of that... and would open up the possibility of adding the same kind of masking to existing sensor calls. In terms of scripting, sensors are in many ways lighter because you're not having to pass around (and copy) lists.
- There's some comments about speed of response, but also about having to throttle it to once per frame. I think the sensor API would make that less of an issue. -- Argent Stonecutter 20:09, 11 July 2010 (UTC)
- I'm undecided about use of the sensor() event. The main reason being that many of the cases where I see this function being used for simple AI behaviours you are almost certainly going to be calling llCastRay() from within the sensor() event, so having to then cache the original sensor data and wait for the second event is incredibly messy. On the other hand, I do agree that it does feel a lot like a special case of sensor so it would make sense to use the event, allowing with suitable
llDetected*()
functions for the extra data such as llDetectedNormal() which is another long overdue function.
-- Haravikk (talk|contribs) 11:15, 22 October 2010 (UTC)
- I'm undecided about use of the sensor() event. The main reason being that many of the cases where I see this function being used for simple AI behaviours you are almost certainly going to be calling llCastRay() from within the sensor() event, so having to then cache the original sensor data and wait for the second event is incredibly messy. On the other hand, I do agree that it does feel a lot like a special case of sensor so it would make sense to use the event, allowing with suitable
llSonar please?
I would appreciate if you took in consideration my suggestions at http://jira.secondlife.com/browse/SVC-2486 please; any feedback is more than welcome.
ps:llCastRay is already awesome, you rock! Please try the hardest you can to figure out how to get this to come to the maingrid with the least crippling as possible.
--TigroSpottystripes Katsu 03:01, 3 July 2010 (UTC)
Hi Tigro,
If I understand your feature request, it sounds much like the shape cast described in SVC-5381 (http://jira.secondlife.com/browse/SVC-5381) for a sphere or a cylinder cast along its primary axis. Is that correct?
Thanks, Falcon Linden
- I have just skimmed thru the comments there, do shape casting allow for somthing liek for example have a nonphys object recognize the geometry so it could rest against a jumbled pile of prims as if it was laying against them physicly? (in the ASCII art in SVC-2486 it would be having the object represented by the O's resting in the diagonal line as if it was solid) --TigroSpottystripes Katsu 05:44, 3 July 2010 (UTC)
- A practical example, imagine a giant mecha, with big flat feet, now imagine a landscape littered with prims of all sorts of shapes and sizes, to make it look realistic, on each step the foot should be rotated to rest against the highest points under it ; just raycasting you have the risk of shooting between prims, and with shapecast you don't get the rotation for the foot. --TigroSpottystripes Katsu 03:04, 4 July 2010 (UTC)
While I realize that this has been "shelved until further notice", I just wanted to pitch in and say I'd definitely like a shapecast option. I am more interested in this for general "spatial awareness" than for combat purpose, so a shape would be very useful for things like finding the highest point in an area, or checking if openings are big enough to pass through.
Tali Rosca 00:52, 27 September 2010 (UTC)
What am I looking at?
A function I just threw in to replace phantom bullets for quickly acquiring a point of interest -- whatever your camera's focused on (in this sim, within 20m) is returned, allowing quicker, more intuitive targeting of other objects. PERMISSION_TRACK_CAMERA must be previously set.
<lsl>key camPing() {
// End points at the camera and 20m in front of it vector camPos = llGetCameraPos(); // Clamp the end position to within the sim // From an SLUniverse post by Chalice Yao // http://www.sluniverse.com/php/vb/scripting/46344-llcastray-available-testing-maybe-only.html#post969497 float xSteps; float ySteps; vector camRot = llRot2Fwd(llGetCameraRot()); fXSteps = llAbs( ( 256.0 * !!camRot.x ) - camPos.x ) / camRot.x; fYSteps = llAbs( ( 256.0 * !!camRot.y ) - camPos.y ) / camRot.y; if(xSteps > ySteps) xSteps = ySteps; if ( xSteps > 20.0 ) xSteps = 20.0
// Cast the ray; ignore hits on land, otherwise get the root key list contacts = llCastRay( camPos, camPos + ( camRot * xSteps ), RC_REJECT_LAND, RC_GET_ROOT_KEY );
// Return values if ( llList2Integer( contacts, -1 ) > 0 ) { // Got a return return llList2Key( contacts, 0 ); } return NULL_KEY;
} </lsl>
Jack Abraham 06:10, 7 July 2010 (UTC)
RC_GET_LINK_NUM? Not RC_GET_LINK_KEY?
I can't think of a circumstance where knowing the link number of the return would be useful. UUID of the prim hit would be far more useful; is that within the realm of possibility? Jack Abraham 04:47, 3 July 2010 (UTC)
Hi Jack,
The default behavior is to return the UUID of the prim hit. If you want the root key instead, you have to use RC_GET_ROOT_KEY. The intended purpose of RC_GET_LINK_NUM was for scripts like your camera targeting system where it is expected that the camera will be pointed at a child of the linkset performing the cast. For example, suppose you make a minesweeper game where each tile is a prim in the linkset. And suppose you script it so that the use can select a tile by focusing on it and clicking. The script could cast a ray from the camera and determine the link number of the tile in the player's line of sight. Then it could use that link number in an llMessageLinked or some other LSL function to modify the appropriate child prim. Does that make sense? If it turns out no one has any use for RC_GET_LINK_NUM, I'll eliminate it for the sake of simplicity. But the behavior you're looking for is already there by default! Yay.
Cheers, Falcon Linden
Makes perfect sense; I need to read better. Thanks. Jack Abraham 05:44, 3 July 2010 (UTC)
Memory concerns
Dumping all possible avaible information into a list regardless of whether any of them will be used seems severely wasteful. If you really need to dump all the info as soon as the command is called straight into script memory, at least do somthing like adding a parameter to the command that is a list where each item identifies which pieces of information the scripter wants (like with llGetPrimtiveParams ) --TigroSpottystripes Katsu 05:51, 3 July 2010 (UTC)
I think we basically have that, Tigro; we only get UUID and hit position unless we set additional flags. Falcon indicated that we will not get all hits in the final version; that'll further reduce the size of the list. Jack Abraham 07:50, 3 July 2010 (UTC)
Clamping
It would be a waste of server resources if every script has to add clamping code to make sure their begin and end are inside the region! Instead, do not return an error code but just stop and return only the hits inside the region. That might mean you have to add the clamping code in the server, but that would be a hell of a lot more efficient than doing that in the LSL scripts.
Note that clamping is relatively easy, in C++ it shouldn't cost more than a few microseconds. The algorithm would be something like:
1) A bounding box can be given with two vectors: bbmin and bbmax, where bbmin is the bottom, south/west corner of the sim (0,0,0), and bbmax the upper, north/east corner of the sim (256,256,4096).
2) Let the ray begin at vector begin and end at vector end (using the same coordinate system as the bounding box).
3) Calculate bbmine = bbmin - end, and bbmaxe = bbmax - end. Check if end is outside the sim, so clamping is needed at all, by checking that at least one coordinate in bbmine is positive or one coordinate in bbmaxe is negative (set 'clamping_needed').
4) Shift coordinates so that begin becomes the origin and end becomes the direction (bbmin -= begin; bbmax -= begin; dir = end - begin). Lets call end dir from now on.
5) Check that bbmin has three negative coordinates and bbmax has three positive coordinates. If not then begin is outside the bounding box (if the signs are correct, except there are one or more zeroes, it's on the border and you can just return begin). Not sure if you should return an error code or return just no results. Finally, if begin is outside the bounding box, but end was inside, you might want to clamp begin instead of end. Lets assume that begin is inside the bounding box for now. If end was also inside it, then no clamping is needed and we stop here.
6) Clamping is needed. Calculate dir.x / bbmin.x, dir.x / bbmax.x, dir.y / bbmin.y, dir.y / bbmax.y, dir.z / bbmin.z and dir.z / bbmax.z.
7) Find the largest value 'max' of those six and return begin + dir / max as the collision point of the ray in the direction dir.
As you can see, this is a very fast routine. Still, I think it should be added to the server side. I didn't add code in order to avoid any license problems ;)
Aleric Inglewood 12:00, 3 July 2010 (UTC)
Actually, using SSE2, clamping would take just a few cpu instructions. It's not a question of efficiency for me, it's a question of future compatibility. Since we don't have script versioning for LSL, if we later add the ability to cast rays between sims or change the size of a region, existing scripts will break. I've been thinking of adding a version parameter to this function in order to deal with that possibility, in which case I could clamp in native code.
Cheers Falcon Linden 17:20, 3 July 2010 (UTC)
- Definitely, clamping in native code rather than LSL is very desirable. I'm thinking a version parameter would be best done as a way of accessing old behaviors, similarly to how we have legacy prim types in llSetPrimitiveParams, and optional for the latest version. What do y'allz think?
- --Michelle Resistance 15:37, 8 July 2010 (UTC)
return also types casted
since filters RC_REJECT_AGENTS, RC_REJECT_PHYSICAL, RC_REJECT_NONPHYSICAL, and RC_REJECT_LAND are used, and therefore detected, it would be handy if in the results returned, the status AGENT, NON_PHYSICAL, PHYSICAL and LAND would also be returned. Is it douable ? --
I've been thinking about that. Either I'll somehow include the type in the list of returned data (perhaps only if you add the flag RC_GET_TYPE or something) or else modify llGetObjectDetails to return the data. You'll definitely have access one way or the other. Regarding land, though, you can definitively identify that because it will return null UUID.
Falcon Linden 17:20, 3 July 2010 (UTC)
Meep
Heya Falcon, really would absolutely love to have an llCastRay function in production.
I saw you had a concern of versioning issues. To overcome that, I heavily recommend using a list as an input, as that would be far more flexible on the kind of parameters and options you can push through rather than fooling yourself into using a hardcoded structure of llCastRay(vector start, vector end, other stuff) etc. A bit like how llSetPrimitiveParams works basically. For example in the past, LL upgraded the prim type interface from legacy to a more advanced and flexible set of input (torii, tubes and rings, yey), they could do this easily because a list was used as a parameter in the function, instead of having to expend resources on adding more functions, bloating LSL and causing legacy issues.
I also have a question, when you cast a ray and it hits an avatar, that hits the avatars' actual sphere-ish phys mesh, correct?
I have actually experimented personally with LSL and my custom client with a prototype LSL Script API, I could offload raycast processing into nearby clients easily and even built a half-working hexapod spider that can walk on a prim landscape, as well as all the fun raycasting combat gun stuff :). So, I have some serious experience to share in this field and having the raycasts locally processed would be really useful in a more timely manner (rather than suffering the delays of network lag).
What are your thoughts on the kind of filtering? Whitelist versus Blacklist? Whitelists are apparently more effective based on desire. (Would be good for consistency (which is hard enough to come by..): llSensors, llListen, ...)
On a last note, you might be wondering about my achievement with my custom client, I couldn't get raycasting weapons taking off because there is a missing critical element to gameplay: Tracers. The user of a gun MUST be able to see WHERE their bullets went (guns use fire cone spread algorithms for added realism). This is one of the significant problems that keep raycasting usage in weaponry really taking off. Otherwise I could have seriously introduced raycasting and changed the face of SL combat with my custom client. If only particle systems could be spontaneously created midair (without requiring the particle system to be 'attached' to the prim (it's possible code-wise in the client btw)) via scripts to simulate tracer effects, then raycasting would seriously be able to take off socially.
--Nexii Malthus 02:10, 4 July 2010 (UTC)
Hi Nexii,
Let me take these one at a time. First, in regard to versioning, LSL lists are very inefficient on the C++ side. They're implemented as linked lists (yuck). I do see the advantage to using a list for parameters, but it would make parsing it slower and I'd rather pull a Windows API (heh, also yuck) style move and (a) add a reserved version number parameter and (b) if necessary later, create an llCastRayEx function. Not the world's most extensible implementation, but c'est la vie.
Second, an avatar's shape isn't sphere shaped at all...and it's not a mesh, it's a convex hull. Its basic shape is kind of like a capsule. I'll leave the process of determining its exact shape via llCastRay calls with RC_GET_NORMAL as an exercise to the reader. :) (And if you do it, be sure to post pictures! That would rock.)
Third, I'm pushing hard for LL to provide client side prediction/client side physics. Although that wouldn't immediately lead to client side scripting, it eventually might. And in the meantime, although open source viewers would need to replace the physics module with an open source version (of which there are plenty), you would have a framework for doing physics-based raycasts locally.
Fourth, regarding filtering, it just made the most sense to use blacklists as it's most common to want to know "What's the first thing I'm hitting?" It's less common to want to know "what's the first avatar/prim/land triangle that I'm hitting?"
Finally, after seeing your comment about tracers I looked up the details of llParticleSystem and was astonished to see that, as far as I could tell, you're totally right. Here's one idea as a temporary workaround: rez a transparent, phantom, nonphysical sphere (perfect, solid spheres are the simplest physics shape available) at the location you need your particle effect, create it there, and then call llDie(). It sucks, I know, but I'm not a graphics programmer and can't add an appropriate particle system function. Another idea, though much much less efficient, would be to rez a set of long, colored, phantom cylinders the length of the raycast. It's still much more efficient than prim bullets since it would be nonphysical and phantom, though.
Hope that helps, Falcon Linden 05:44, 4 July 2010 (UTC)
Rendering of what the standing and ground sitting av shapes are!
--Moy Loon
- Hahahahah, awesome! :D
- btw, can you repeat this but with a crouching av as well to confirm there is no change when an av crouches please? --TigroSpottystripes Katsu 18:35, 24 July 2010 (UTC)
I already know that crouching avs have no change, The sitting on a prim is different than the ground sit though! --Moy
Function to not fail, what do you think?
I made this:
<lsl>list JustRayIt(vector start, vector end, integer filter, integer flags) {
list temp; while((llList2Integer(temp, -1) < 0) || (llGetListLength(temp) == 0)) { temp = llCastRay(start, end, filter, flags); } return temp;
} </lsl>
The idea being to halt the rest of the script until it can get a valid trace; does it work the way i intended it to? Is there any downside to using this? Is there a better way to get the same result? --TigroSpottystripes Katsu 04:14, 4 July 2010 (UTC)
Hi Tigro,
The script you're suggesting would, sadly, be hugely inefficient. It would hog system resources until the script's time slice ran out. And, to make matters worse, once you fail you're guaranteed not succeed until at least the next frame anyway. I'm not a huge lsl scripter, so I'm not 100% sure, but I believe if you added an llSleep(0) call in the while loop, your script would be put to sleep until the next frame. Failing that, try llSleep(0.1) or some other small number.
Good luck, Falcon Linden 05:29, 4 July 2010 (UTC)
- The way it is on the Oatmeals, do tracing ever fail in the frame? --TigroSpottystripes Katsu 05:40, 4 July 2010 (UTC)
- Also, doesn't llSleep hog systems resources just the same? --TigroSpottystripes Katsu 05:44, 4 July 2010 (UTC)
On Oatmeal, casts will fail if the overall physics FPS drops too low. It will never fail due to too many raycasts in the same frame, however. In production it will, but I wanted to see how people used it before determining appropriate limits.
llSleep stops execution of your script and allows the simulator to move on to processing another script. It is not implemented as a busy-wait. (At least, I sure hope not. I haven't actually checked the code.)
Falcon Linden 05:50, 4 July 2010 (UTC)
- How about this version?
<lsl> list JustRayIt(vector start, vector end, integer filter, integer flags) {
list temp; while((llList2Integer(temp, -1) < 0) || (llGetListLength(temp) == 0)) { llSleep(0); temp = llCastRay(start, end, filter, flags); } if(llGetListLength(temp) == 1) temp = [NULL_KEY,end, llVecNorm(end-start), 0]; return temp;
} </lsl>
- It got the sleep as you suggested, and if it doesn't hit anything in range it still returns a key, a hit position, a normal (so it kinda works like a telescopic feeler, when not reaching anythign it eventually stops at maximum extension with no deflection), while still keeping llList2Integer(theraylist, -1) == 0
--TigroSpottystripes Katsu 19:43, 7 July 2010 (UTC)
- Ok, i finally managed to get it to wrok right, i think, but hsould i keep posting here clogging the talk page?
Partially offtopic: about SVC-4606 "Surface conveyour belt"
Falcon, if it's not you, could you please bring SVC-4606 to the attention of whatever Linden that would be able to evaluate it and get it in the plans if it's possible please? (If it's you, then please take a look and see what you can do) --TigroSpottystripes Katsu 04:43, 4 July 2010 (UTC)
I have thought about adding a much, much simpler version of this (where you simply get to specify a velocity vector and a face of the prim), but it would be at least a little tricky to implement and there are a number of things of more general use that I'd like to get to first. Some day, though, it would be a great feature. Falcon Linden 05:51, 4 July 2010 (UTC)
- If the server already knows about which face collided and things like the normal of the collision point (and of course the texture parameters of the prim), wouldn't it be just a matter of basic vector math to get the resulting force and stuff? I imagine this could be a game changer close to the scale of flexies, people moving around a mall on flat conveyors like those on some airports, working escalators, more realistic wheeled and tracked vehicle behavior, people will find all sorts of uses for it. Is there somewhere i can see the stuff you got planned? --TigroSpottystripes Katsu 06:01, 4 July 2010 (UTC)
I'm about to head out (it IS a Saturday night here, haha), so this is probably my last post, at least for a few hours, probably until tomorrow. The problem is related to stability and details about determining which objects to apply the force to and how. In the physics engine, this would be done by modifying the contact points between the conveyor belt and the other bodies. Also, the server doesn't really know which face collided, which makes it trickier still, as that info would have to be derived dynamically any time a body came in contact with the conveyor belt object. Finally, it would almost certainly break avatar animations which rely on the avatar's velocity (not the requested motion of the user) to determine when to play a particular animation. Unfortunately, I don't have a publicly visible list of projects I'd like to complete. But they do include llCastRay (yay progress!), llCastShape (see SVC-5389...I think...the raycast SVC, exposing the Havok vehicle kit, providing for alternative physics representation (so that the shape you see isn't tied to the shape the physics engine sees, allowing simpler collision geometry), providing control of friction, density, restitution, and gravity, ... the list goes on. Please bear in mind, however, that there is absolutely no guarantee any of these will be shipped as they are mostly unscheduled it isn't clear what LL's priorities will be in the coming months. Oh, and of course, given the opportunity, I'd put all of these ideas aside to work on client side prediction which would have HUGE impact on lag, although it wouldn't provide much in the way of new resident-facing features.
Have a good night, Falcon Linden 06:24, 4 July 2010 (UTC)
That partial list of projects is, like, my wishlist as an LSL scripter. You're my new favorite Linden. ^_^; --Michelle Resistance 15:44, 8 July 2010 (UTC)
- Some of those are among the feature suggestions i've filled on pjira :)
- Falcon rocks indeed!! --TigroSpottystripes Katsu 16:10, 8 July 2010 (UTC)
selfignoring?
Is there a way to have the raytrace ignore prims in the same linkset? --TigroSpottystripes Katsu 05:42, 4 July 2010 (UTC)
No, unfortunately this is not possible and would be hacky to implement (though it could be done if there were enough demand for it). It will, however, always ignore a shape that the ray begins inside of. So if you use llGetPos() from a convex prim, that prim will not be returned by the cast. You can always use the UUID of the prim to ignore the result as well.
Falcon Linden 05:46, 4 July 2010 (UTC)
I'm not sure if it's too late, but I would really enjoy this, as I'm working on a game where the root prim that sends the raycast is usually in the center (for pivot reasons), and raycast might return the sender UUID a bunch of times. And I don't think raycasts with 5-6 hits is very efficient. I'll experiment a bit with setting phantom or physics for a fraction of a second while the raycast occurs, but in the future a RC_REJECT_SELF or similar would be awesome. --Jasdac Stockholm 04:46, 18 September 2011 (PDT)
On the topic of limiting it to not work past a distance
It was done with llSensor, and what happened? People wasted server resources to overcome the limitation; you still think it's a good idea? --TigroSpottystripes Katsu 08:04, 4 July 2010 (UTC)
Nope. I don't. But llCastRay isn't artificially limited to a distance. It's simply limited to work within the region. But that isn't an artificial limit, it's a fundamental one: llCastRay uses the physics engine for raycasts. On a given simulator, nothing exists in the physics world outside the region boundaries.
Falcon Linden 09:47, 4 July 2010 (UTC)
- Hm, sorry, i'm not finding it now, but i could swear i had read you saying somthing along the lines of "you wouldn't want people raycasting from the other side of the sim", dunno... --TigroSpottystripes Katsu 09:56, 4 July 2010 (UTC)
Yes, I did say that. I then proceeded to change my mind. :) Falcon Linden 18:59, 4 July 2010 (UTC)
Is it a logical bug on my script or does it not update fast enough?
Does the data llCastRay reads from gets update as often as the position and rotation of phys objects or does it get updated less often? I'm mostly confident that the start position is inside the prim but somtimes the trace will hit the prim somehow, it happens more often when the prim is bouncing around fast. --TigroSpottystripes Katsu 11:23, 4 July 2010 (UTC)
That depends on how you're updating the objects. If you're calling llSetPos() or similar in your script, those updates will not be processed until later, whereas the llCastRay call will be processed immediately. I suspect llGetPos() will return the value you set with llSetPos() even though the physics object isn't there yet. Falcon Linden 19:01, 4 July 2010 (UTC)
"I'm personally praying that llCastRay will make simulated projectile weapons essentially obsolete in SL. "
I've spent a little time exploring the functionality of llCastRay today. From the perspective of a veteran LL damage combat scripter;
In terms of raw utility, llCastRay effectively provides the ability to determine a bullet's target without the intervening physics. This is an advantage because it means that traditional region crawl caused by irresponsible people spamming physical objects is significantly reduced. It also means that the number of bullets required to send an individual home is reduced; in the case of the firer being able to aim, of course.
The function seems more fitted to abstracted combat with meters and script awareness (determining distance to surfaces, etc) however, because it provides a very large volume of data back to the script calling it but does not impact what it is detecting in any way. While it is possible to build a weapon that uses it for projectiles with traditional LL damage, the benefits do not necessarily outweigh the negatives; it effectively moves the majority of work from the source system to the projectiles instead. Using communications such as listens to transfer a target vector from a gun to a bullet on each rez is obviously absurdly inefficient considering the rates at which most people like to fire them and therefore the cast is better placed in the bullets themselves; this means that the bullets cannot be temporary prior to casting and therefore realistically on rez, although they can simply be set temporary subsequent to casting. Regardless of the method of acquiring the target position, the bullet must still travel to the location to inflict damage; a stacked primparams position is the obvious solution, as it also allows for temponrez and physics to be set in the same call.
Would it be possible to implement a sister (if somewhat crippled) function to llCastRay that has the capability to inflict LL damage on agents? While I see a great deal of value in llCastRay it is not necessarily preferable to physics as a combat tool. Something along the lines of an llCastDamage which is restricted to cast from the root position of the object calling it along a fixed axis. In a similar manner to a sensor, except with a damage variable similar to the llDamage() prim param setter that affects only the first thing it intersects. Additional fluff could be a contact sound triggered at the point of intersection, contact particles and so forth.
tested projectile, just for reference: <lsl> vector xyz(vector in) {
if (in.x > 255.9) in.x = 255.9; else if (in.x < 0.1) in.x = 0.1; if (in.y > 255.9) in.y = 255.9; else if (in.y < 0.1) in.y = 0.1; if (in.z > 4095.9) in.z = 4095.9; else if (in.z < 0.1) in.z = 0.1; return in;
}
default {
state_entry() { llCollisionSound("",0.0); llCollisionSprite(""); llSetDamage(100.0); } on_rez(integer s) { if (!s) return; vector p = llGetPos(); vector d = <20.0,0.0,0.0>*llGetRot(); list ray = llCastRay(p,xyz(p+d),0,0); list tgt = [PRIM_POSITION,llList2Vector(ray,1)]; tgt += tgt += tgt += tgt += tgt += tgt;//1,2,4,8etc llSetLinkPrimitiveParamsFast(LINK_THIS,[PRIM_TEMP_ON_REZ,TRUE]+tgt+[PRIM_PHYSICS,TRUE]); llDie(); }
} </lsl> Jeremy Duport 19:51, 4 July 2010 (UTC)
This is *not* a viable replacement for projectiles
llCastRay is a great idea, and I'll make heavy use of it in a wide range of applications, but there's no way it's going to replace scripted bullets in any meaningful way.
There's just no other way to get a decent visual effect for bullets. Particles are an enormous performance drain on the client [and don't anyone tell me to just get a better machine, I'm a poor student, damnit], and of course look the same from every direction. Scripted bullets are also the only timely way to get a particle effect at unscripted impact locations.
There's also the problem of communicating effectively between a gun and a scripted target. With combat going on, something like a listen on targets and regionsay from guns is going to trigger zillions of unnecessary events. Sure, *I* know how to properly hash UUIDs to integers, and there's reasonable code for that on this wiki, but have you actually seen the kind of shit most scripters in SL try to pull? Note that people are *still* using resizer scripts in every prim of a linkset and controlling them with linked messages.
Also, despite being sidetracked by https://jira.secondlife.com/browse/SVC-5953, I'm a week or so of work away from releasing several weapons that trigger bullet rezzes via changed events, rather than by inked messages. Tyro Dreamscape has already successfully demonstrated this method as a near-zero-sim-impact way of squeezing high firing rates of scripted bullets out of as few rezzing scripts as possible. Sure, you could bring up sim garbage collector woes, or my argument from above about the absurdly low coding standards among scripters, but the former has not been an issue in practice, at least with intentionally minimalist bullet scripts, and the latter is something I'm expecting market forces to help with. We *can* do scripted bullets the right way.
I'd really like someone to prove me wrong. Thoughts?
--Michelle Resistance 15:55, 5 July 2010 (UTC)
Ummm, you do realize that you're still just calling a function in one script, that triggers an event in another, right? Except that where a linked message merely communicates between scripts, the changed() event requires triggering a function that changes some parameter of the other object, so you're asking the simulator to do a small bit of extra unnecessary work in between calling the function and triggering the event.
You are right that scripted bullets can be done the right way. But the right way doesn't mean reinventing the wheel or creating a Rube Goldberg machine, it requres understanding what the wrong way is, why certain things use extra processing resources, and finding the most effective ways to mitigate those problems. Keep in mind that people have tried to use llResetOtherScript() and actually believed that it was more efficient. It was the same sort of reasoning involved, where someone thought "method A is laggy, therefore method B will be better."
It is quite possible to make efficient physical projectile weapons. But just because many people are unable to do so does not mean that you need to find some supersekret new method for doing so. It is simply a matter of using good coding practices like KISS. Granted, it's oh so much easier to market something that's new and different, but that doesn't make it so.
Jahar Aabye 19:24, 5 July 2010 (UTC)
Passing data through a changed event, at least the way Tyro and I have been doing it, has far less impact on the sim than the string operations that most people do when communicating between scripts via link messages. Try it, it's rather impressive. And, to dispel concerns that it's just a gimmick, I'll explain exactly what I'm doing and (probably) why it works better.
I've got a main script and several rezzer "thread" scripts, all in the same prim (they don't need to be, but that's how I'm doing it), a hollow sphere. When a user pulls the trigger (or an automated weapon decides to open fire), llSetColor(<AUTO, timer, aim>) is called [llSetLinkColor also works, though llSetLinkPrimitiveParams and the fast variant don't, as they don't trigger a changed event], where AUTO is a predefined floating-point number identifying that it's a firing order, timer is the argument we want the thread to past to llSetTimerEvent to control the firing rate, and aim is either 1.0 or 0.0, signifying if I'm using the prim's other face to provide additional data about where to aim the bullets (which we can do without triggering a second changed event, if the llSetColor call for the other face is done immediately before or after the firing-order call). This has been significantly more responsive (in LSO, anyhow) than a linked message in all my tests, and can easily support rather egregious firing rates [~25 bullets per second with five threads - well under the goo fence limit, though probably more than you'd want] from many simultaneous users without affecting sim FPS. My team's theory, that led us to try this in the firs place, was that the link_message dispatch code on the sim side is slowed by argument passing and filtering in a way that the changed event is not. That we're only performing floating-point operations when using face color as an argument buffer seems to make the difference. Certainly, one could use the link_message integer parameter to do filtering, and I write all my APIs that way, but it appears the extra overhead of passing string and key arguments, even when not used, is enough to upset the sim when performed at high speed. As a side benefit, using the changed event keeps the rezzer threads from needing link_message handlers, reducing the number of scripts that need to filter out other communication happening in the linkset.
Hope that allays your concerns. If not, I'll be here all week. ~_^
--Michelle Resistance 23:06, 5 July 2010 (UTC)
- Well yes, you're simply shifting a portion of the load from the VM (which would handle the linked messages) to the Database and Simulator (which are handling the altering of the primitive's parameters and which then triggers the VM's changed() event). This does not make it particularly more efficient, as I mentioned before you still have a function call and an event triggered, you're merely routing it through another method, in this case the simulator, which has to then alert every client within draw/LOD distance as to the nature of the change. I am fully aware of what you are doing and how you are doing it, you are at least the third person in as many years who has mentioned it.
- Rather than a lecture on how to script guns, I'll simply say that if it works for you, then that's all that matters. There are efficient ways to use linked messages, and there are incredibly inefficient ways to use linked messages. Similarly, I am certain that people will find right ways and wrong ways to handle llRayCast() if it is ever implemented. Incorrect methods will undoubtedly spread through the grapevine with assurances that "this supersekrit way is teh best evar!!!11!!" Market forces have as of yet had minimal effect on poor scripting with regards to guns in SL, I wouldn't expect that to change at any time in the future. As you correctly note, many fashion designers still put resize scripts into every prim of hair.
- In some respects, I doubt that many amateur gun scriptors will be much different after raycasting than before. It may be less likely to be used by many amateur gun scripters simply because the default LL Damage system is built around physical collisions, and presumably that would remain the same. Also, combat systems that use raycasting would likely require at least a decent understanding LSL or else might use prewritten no-mod scripts to do the raycasting. To that extent, I do worry that raycasting may appear to be more efficient when it debuts on the grid, if only because of self-selection in terms of who is using it and how it is used. This is probably something that should be considered if llCastRay() is ever implemented, as it does have an effect on how to interpret any sort of metrics gathered when trying to determine its relative efficiency compared to bullet-based guns.
- In the end, it will be one more tool. I would hope that the devs at LL do not really think that this will completely replace physical projectiles, but it is nice to have the option. Similarly, I do hope that people understand that the relative efficiency of various guns on the grid varies wildly, and that the scriptor has a far greater impact on the relative efficiency of a gun than whether it uses physical bullets or llCastRay() when it is implemented.
Jahar Aabye 00:18, 6 July 2010 (UTC)
- Latelly i've been using llTarget and not_at_target to have stuff run as fast as the server allows without actually using somthing like while(true) --TigroSpottystripes Katsu 00:31, 6 July 2010 (UTC)
- In my tests, I've found that LSO loops seem to end up *slower* than repeating events like timers and not_at_target. 'Sweird. --Michelle Resistance 00:47, 6 July 2010 (UTC)
- Latelly i've been using llTarget and not_at_target to have stuff run as fast as the server allows without actually using somthing like while(true) --TigroSpottystripes Katsu 00:31, 6 July 2010 (UTC)
- You could use llRayCast to verify if the aiming hits anyone,and then rez a "bullet", posJump it to the target and make it phys to collide if you wanna use collisions to relay hits. --TigroSpottystripes Katsu 23:57, 5 July 2010 (UTC)
- Actually, that would probably be the worst of all worlds. You're still rezzing a bullet, still moving it to the target, still making it physical, still colliding it. All of the things that llCastRay() is attempting to prevent. Also, most combat systems that involve collisions limit (or should limit) the minimum velocity of a collision. To get around this, one would probably have to add a call to llApplyImpulse() or something similar. At the end of the day, you wind up with a situation not much better off than just firing a bullet.
- llCastRay() is probably best implemented in a combat system in a manner similar to current sensor-based combat systems, which have been around for years. I'm not sure that sensor-based (or raycasting-based) combat is any better or worse than physical bullet-based combat. Each has different tradeoffs, and at the end of the day it's going to come down to how these functions are worked into the system that gets set up. Whether using sensors, raycasting, or bullets, it's all about understanding the strengths and weaknesses of each system, and working with that in mind. Raycasting does have some significant strengths, but only if you take advantage of them. Raycasting, if done correctly, will probably take some load off the physics engine at the possible cost of runtime efficiency and memory. Physical bullet systems are simpler and may have an advantage in terms of runtime efficiency and memory use if done correctly, at the expense of offloading more of the work on the physics engine that has to deal with all of the active objects and the collisions generated.
Jahar Aabye 00:18, 6 July 2010 (UTC)
Ahoy folks!
I don't know enough about the issues in LSL to comment on most of the topics brought up in this thread. But with regard to the issues around the appearance of raycasts vs rezzed bullets, once you use llCastRay, you'll at least be able to set your bullets phantom. This prevents the physics engine from needing to check for collisions with anything but the land. Unfortunately, due to an old bug, collision checks against the ground are still very expensive. We expect to fix this by 1.44 at the latest. Once that's done, phantom bullets will be much more efficient.
- Phantom bullets would give us the problem of having to inform them somehow of a hit so they can [promptly] self-destruct instead of continuing to pass through things… unless you're suggesting the bullets themselves do llCastRay and short circuit the physics system. That sounds like a terrible hack, though. Shouldn't it be more efficient to let the physics engine do its thing, rather than going through the twisty little passages of LSL VMs? --Michelle Resistance 17:02, 6 July 2010 (UTC)
Regarding the matter of rezzing a bullet and then using the posjump trick (assuming that refers to the llSetPrimitiveParams hack where you repeatedly set the prim's position in a second call), that will actually be substantially less inefficient in 1.40 (when we finally get it right!). The reason is that in the past, each time you set the prim's position, the physics world would be updated, sometimes many many times in a frame. That is no longer the case (only the final position is actually used).
- "PosJump" actually refers to a different >10m movement hack than what you're talking about, which is known as "WarpPos". PosJump is very much preferable, as the LSL script doesn't have to waste time and memory calculating a series of intermediate steps… but it doesn't work with llSetLinkPrimitiveParamsFast, just the slow variety. --Michelle Resistance 17:02, 6 July 2010 (UTC)
- Last i tried it did work with llSetLinkPrimitiveParamsFast, did you test it yourself? --TigroSpottystripes Katsu 17:31, 6 July 2010 (UTC)
- Yes, just a few weeks ago… though now that I think about it, I could have been confusing the issue with that posjump fails when the object is physical. --Michelle Resistance 16:54, 7 July 2010 (UTC)
- Last i tried it did work with llSetLinkPrimitiveParamsFast, did you test it yourself? --TigroSpottystripes Katsu 17:31, 6 July 2010 (UTC)
And yes, an LSL busy loop (e.g., while(TRUE)) is very, very inefficient. It uses as much of the sim's resources as available until it is cut off for the frame. Even the most inefficient event scheme would probably be better than a busy loop.
Falcon Linden 03:25, 6 July 2010 (UTC)
- I've found that even a bounded for loop is slower than a timer, in practice. Any idea why this might be? --Michelle Resistance 17:02, 6 July 2010 (UTC)
In LSO it makes sense that using changed would be faster than the link_message. The changed event has one parameter, link_message has four; two of which are strings. It takes more computer time to push a link_message event onto a scripts event queue then it does to push a changed event. It takes more time to copy the values into script memory and trigger the event. Mind you, using llSetColor this way is going to cause a huge number of updates that the sim will try and send to all users in sight of the weapon. For a long time I thought we need a better comm event, no string, no key, just a list. Than I latched onto C# and the idea of building custom events. -- Strife (talk|contribs) 16:21, 8 July 2010 (UTC)
Possibility to limit list length?
I am concerned about the memory issues posed by this function. It was mentioned above, but not really fleshed out. In order to be useful for a combat perspective, you can't really set any of the flags (that is, it must return all agents and objects) so that you know whether there is a wall or some other barrier between yourself and the target. This means that you can get a potentially very long list with a UUID and vector position for each object hit. This could easily eat up several kb of script memory.
However, limiting the function to returning the first object hit (as has been mentioned as the possible final version) also removes some potentially interesting uses of this function. For example, you could have a situation where you get one result if it reaches an avatar unimpeded, another if there is a single object between you and the other av, and then no result if there is more than one object.
Would it be possible to compromise, and add another variable to input into the function to select the total number of objects to return? So you could have:
list llCastRay(vector start,vector end,integer filters,integer flags,integer num_returned)
Where num_returned would be the total number of objects hit, starting with the closest. It could be enumerated starting from 0 so as to match the values in the returned list, or from 1 if you would need to use 0 to set it to no limit.
As for this function making physical projectile combat obsolete, I do not believe that this will happen. I see this as akin to how sculpties have enhanced building: they give builders more options and allow for a greater variety of creative designs, but they have not obviated the use of regular prims. Similarly, I think that this feature may increase the options available when developing combat systems and weapons. However, I think that there are advantages to physical projectiles (such as the ability to code for ballistic trajectory). I have used sensor-based combat systems before (although this has many advantages over those as well), and I have found that those feel a bit too much like playing "laser tag" especially when used over longer distances.
I think that this will create more options for combat, it may allow for new types of combat, but there are always tradeoffs inherent in any system. Raycasting methods will have advantages and disadvantages, they will be more efficient in some ways and less in others. It will be nice to have this as a new option, but I worry about overselling this as a complete replacement. After all, the Mono VM was marketed as being the wave of the future that would make LSL-compiled scripts obsolete. While many scriptors knew to be cautious with a new VM, LL's overhyping of the system created a marketing environment where customers were asking if every product was Mono. This resulted in Mono being used in a vast number of situations where it was not only unnecessary but entirely inappropriate.
I worry about a similar situation unfolding here, where marketing llCastRay as a complete replacement for physical projectiles will encourage non-technical people to demand "those new ray guns LL keeps telling us about, why haven't you been making those?" Then these same people will inevitably come back a week later demanding why the RayCast "bullets" behave differently. All that I am asking is that you please acknowledge that non-technical people will read these announcements without understanding the technical nuance and the inherent tradeoffs. Overhyping something as a "complete replacement" when it is a new feature that allows for new options may only wind up creating new headaches. A new feature that opens new doors and allows for new options for creators is great, it is wonderful. No need to oversell a good thing.
Jahar Aabye 19:24, 5 July 2010 (UTC)
In the final version of llCastRay, if more than 1 hit can be returned I'll be sure to give you the ability to select some kind of limit (even if it's only a binary "first hit or all N hits" choice--where N is definitely a finite number determined by the specification).
Also, if using llCastRay feels too much like laser tag, try adding a small delay before the raycast executes or adding some randomness to the cast's direction. As for the ballistic trajectory, if that's really critical, there are ways to simulate it. For example, you could make 4 ray casts approximating the parabolic curve, but you'd have the possibility of performing an early-out if one of the first casts hits something.
Falcon Linden 03:33, 6 July 2010 (UTC)
- Yes, randomness for the direction is easily doable by modifying existing code. What I meant about ballistics isn't just the trajectory, drop, and inaccuracies like random variations in direction. A delay before firing can be done, but one factor in the current projectile combat is that your aim is highly dependent upon the distance to your target and how this relates to the target's movement. With projectiles, it is far easier to hit a close target than a far one, and if the target is moving, this has a disproportionate impact on difficulty with a farther target. This is because of the time that it takes for the bullet to reach the target, because the bullet's travel is not instant.
- Now, because SL physics limits bullet velocity to far less than in real life (our SL bullets are usually 115 m/s while a 5.56mm round from an M16 is well over 900 m/s), the result is that it greatly exaggerates the effects of distance and movement, but distance in SL is always a somewhat arbitrary measurement. So I recognize that physical projectiles are far from perfect, and plenty of people have complained of difficulty when they first try SL combat after experience with other video and computer games that probably are using raytracing or similar technology. But it does add a satisfactory level of difficulty and skill to competitions.
- I know this is probably not feasible, and I certainly don't want it to wind up polluting the code and making everything more difficult, but is there any way to give the ray a specific velocity, rather than being nearly instant? I'm not just talking about a delay between the firing input and casting the ray, but having the ability to set the ray to move at a specified speed so that distance to target matters? I mean, I suppose that I could fire multiple staggered rays to try to imitate this, and have the script read data from each successive ray only between certain distances....but that's gonna get really inefficient really fast, while the simulator is already calculating avatar distance and movement.
--Jahar Aabye 05:47, 7 July 2010 (UTC)
- Hey Jahar, I see what you're saying, but no, there's no way to slow down the ray, it's a synchronous, instantaneous query into the physics world's current state. You'll just need to come up with a new clever way to inject difficulty into things :) (I'm usually terrible at first person shooters and those have stupid AIs and instantaneous raycasts. I'm sure a group of human enemies can find a way to make hitting them challenging while still being fun, even if the bullets travel faster now.) Also, given that the physics hitbox of a player is pretty narrow, I'm guessing it may be harder than you expect to hit a moving target from the other side of the sim, even with a raycast. But then, I haven't tried.
- Falcon Linden 03:46, 8 July 2010 (UTC)
Raycast Damage
Hey folks,
I've been trying to coalesce some of the most significant suggestions for llCastRay, and one theme that seems consistent is that weapon system makers need a way to be notified when hit by a ray. I'm thinking of two possible features:
1) For integration with LL damage, it might be possible to create another parameter that takes a list of parameters (albeit with a bit more strict requirements than in primparams args due to inefficiencies in list processing). In the future, this could include a version number, but in the meantime, one possible parameter could be RC_DAMAGE which would apply a requested amount of damage to the first object hit if that object is an avatar and if the region is damage enabled, etc.
2) An event, ray_impact, that the caster script could choose to trigger in impacted objects. This would, in principle, alleviate many of the security concerns around raycast-based weapons systems. In the interests of full disclosure, however, I should tell you that (a) I don't know how to create a new event (I'll have to speak to Kelly Linden) and therefore, (b), I don't know if implementing this feature would be prohibitive in terms of engineering time. But let's suppose I could implement this. What information would you want the receiving object to be able to obtain in this event? The fewer the better, so my first instinct would be no information (it's enough to know you were hit). Beyond that, knowing the exact location of the hit could be nice, as would knowing the UUID of the casting object (maybe?) and perhaps receiving bit of user data provided in the llCastRay call. Would that be helpful? How might you use it?
Cheers,
Falcon Linden 03:47, 6 July 2010 (UTC)
- #1 sounds excellent, though it's been notoriously difficult to get people to play fair with LL damage.
- A ray_impact event would be a godsend. The UUID of the casting object would be essential, and a hit location [and maybe hit normal] would be very useful. Ideally, an appropriate set of llDetected* functions should work inside the ray_impact event similarly to how they're used in a touch event. Might need a new one, like llDetectedRayNormal. Still, just an event with a signature like ray_impact(key id, vector pos, vector norm) would be massively useful. Let's see… I'd be using llCastRay for collision avoidance on robots, and ray_impact would make it easier for the robots to exhibit schooling behaviors. Similarly, such robots could interact with scripted objects in their environment (door controls, moveable boxes?) elegantly. Other uses… target ranges for raycast-based weapons… missile lock detection in fighter combat… assuming we could use it in attachments for impacts to the avatar, combat meters for raycast-based guns… AR-like user interfaces implemented by raycasts from a HUD [though the math for generating such rays may be rather complicated]… line-of-sight communication between objects and avatars… I'm sure there are more that I can't think of at the moment. Bottom line, adding functionality to LSL is a Very Good Thing. --Michelle Resistance 17:46, 6 July 2010 (UTC)
Falcon, I've been silent on this point because I don't agree with the naysayers; llCastRay is exactly what I've been needing for the combat system I'm building. For those that want to use Linden Damage, I think llTakeDamage() (perhaps accepting negative values to allow for healing) would be valuable, but beyond the scope of this project. I don't personally hold with the logic that it's marginally hard to write non-laggy chat communications, so we should expect people to write non-laggy bullets and guns. It'll require combat to be done differently, so it's not an evolutionary change, but I don't see that as a barrier.
That said, if it can be done, RC_DAMAGE would be a nice thing to have. I do build my weapons to fail down to Linden damage if no supported combat system is found, and if Linden damage is enabled. ray_impact would also be nice, especially if it's only explicitly triggered; UUID, impact point, and an arbitrary integer constant sent by the ray caster would be the values I'd see as most useful. Perhaps rather than go the whole list of parameters route for RC_DAMAGE, just add another integer parameter to llCastRay that would be used differently with different flags? In any event, not having either of these would in no way dampen my enthusiasm for this feature or impact my plans for using it, assuming it gets deployed. Jack Abraham 19:23, 6 July 2010 (UTC)
- I think that suggestion #1, or some similar functionality, would be essential if you want this function to work with the current default LL Damage system. The LL Damage system currently requires a physical collision between an avatar and an object scripted with llSetDamage(). This means that I can simply fire a bullet at an avatar and apply damage, but raycasting alone would not be able to perform any sort of damage without also requiring some sort of bullet unless you add this feature.
- Suggestion #2 also sounds useful, if possible. I suspect that many people will still utilize weapon-meter comms even if you include this function, because there is still greater security there in terms of being able to limit what can do damage within a system. However, Michelle outlines many other excellent uses for including this feature. In addition to making it far easier to construct non-avatar targets, it dramatically increases the potential usage for raycasting beyond just a replacement for projectiles. I was just talking to a plane maker last night about how raycasting could make laser-guided bombs far more interesting, and while that example wouldn't require this extra feature, it does illustrate that raycasting can evolve into so many other things besides just a bullet, and so adding in the feature to detect a raycast may expand the use of raycasting into all sorts of applications beyond what any of us could envision.
- As for what information might need to be passed? Jack's suggestion of adding an all-purpose integer definitely sounds like the most important. Obviously an integer would be required to set damage, and having the ability to send an integer with a raycast would also allow for expanded use outside of LL Damage. It could allow a weapons system to differentiate between raycasts of different "caliber" or allow for raycasts to broadcast a "team" number, or to differentiate between raycasts being used as "projectiles" from those being used as "lasers" or in some other sensing capacity, or a million other situations where the ability to program an object with multiple responses to a raycast would dramatically expand its utility. An integer is also the simplest piece of information that could be added, and you'll need to add it anyways if you add LL Damage functionality.
- The UUID of the originating object would also be useful, as would the owner's UUID. While it may sound redundant, I wonder about situations where the owner of the originating object might not be in the region, I believe that llGetOwnerKey() may not work in those situations, right? So the owner UUID would be important. It might also be useful for llCastRay() to send a UUID of its own choosing, and here I'm thinking of how it is common in SL aviation for planes to be guest-flyable, so the owner of the object may not be the one using it. However, workarounds already exist for this with bullet-based combat systems, so maybe it's not essential. Of course, if it simply broadcast a UUID (or string) of the scriptor's choosing, that would allow whoever is scripting the object to decide whether to send the object UUID, the owner UUID, or the user's UUID, so it might be even better than automatically sending the object and owner UUIDs.
- Finally, it might be useful to include the vector position of the originating point of the raycast. Not where it hits you, but where it was sent from. Granted, if the object/owner/user UUID is included, then llGetObjectDetails() might be used to get this information, but for some instinctive reason that I can't quite figure out at the moment, I feel like this might be a useful thing to add. In the end, though, if you have to include one bit of information, make it all purpose integer that could be used to determine LL Damage or passed to an event. If at the end of the day you can only pass on one piece of info, an integer would give you the most utility with the least overhead.
- Jahar Aabye 06:43, 7 July 2010 (UTC)
- How about the shooter just sending the info about how the shot originated (also thigns like the gun used etc) via chat and then the potential target(s) calculate whether they were hit or not and adjust their owner health points as needed? (I just thought about that approach, haven't put much thought into it)
- Btw, does everyone uses gravitiless bullets? I would expect people going for the more realistic stuff would use physical bullets that fly a ballistic trajectory... Can a ballistic arc be used instead of a straight line "ray" with raycasting? --TigroSpottystripes Katsu 06:56, 7 July 2010 (UTC)
- Tigro, in real life, a 9mm round of typical self-defense ammunition has a muzzle velocity of 1120ft/s or 340m/s. As another commenter pointed out, a 5.56 NATO round (think M16) has a muzzle velocity of about 3000ft/s or 915m/s. Those two rounds would travel a sim diagonal (362m) in 1.06 and 0.4s, respectively. During that time period, if fired horizontally, they would fall about 5.5m and about 0.79m, respectively. Sounds like a lot, except that a pistol wouldn't have a range anywhere near that large in reality (you couldn't POSSIBLY aim a pistol accurately at a target nearly 4 football fields away, at least not by hand, and not without some kind of crazy scope...not to mention that wind would slow it down substantially over that distance) and for the M16, the drop is not significant given the 350m distance being traveled. So while no, you can't use a ballistic arc instead of a straight line, think about whether you really need to. And if you discover you really do, you could always approximate it with 4 line segments.
- Falcon Linden 04:04, 8 July 2010 (UTC)
Get Alt-Zoom camera cursor position and surface orientation
Here is an example I made, how to get the camera cursor position when you Alt-Zoom on any object surface with the llCastRay function.
The script also calculates the surface orientation at the cursor position and rezes a prim on a top of surface. The Z-Axis of a rezed prim is aligned with the Normal vector of a surface at a given point and the X-Axis points in a way of your camera sight.
To test the script make a new HUD object and put the script below into it. Also put one standard cube prim (named Object) into its inventory. Attach the HUD and Alt-Zoom to any curved surface in region, but not more than 10m far from you. Then click on the HUD and a new prim will be rezed on a top of surface where the Alt-Zoom cursor of your camera points.
<lsl> // // Scriptname: Get Alt-Zoom position and Surface Orentation // Version: 1.0 // Date: 06.07.2010 // // Description: Gets the position of the camera cursor // when a user Alt-Zumes on a surface of any object and // rezes a prim on this point and orients it with a surface // // How To: - Create a new HUD (cube), size = X=0.05 y=0.05 Z=0.05 // - Put this script on it and attach it as a HUD // - Insert a standard prim (Cube 0.5m) into HUD inventory (named as Object) // - Alt-Zoom with your mouse to any object surface in the region // - Without moving your camera, click on this HUD // - You will get the camera cursor position and surface orentation // - An Object from HUD inventory will be rezed on a top of Alt-Zoomed surface // perfectly aligned with surface and with X-axis pointed to your line of sight // // Tips: To see the camera cursor, enable: Advanced->Character->Show Look At in your Advaned Menu // Rez a big sphere to make a curved surface in a region and Alt-Zoom on it. // // Notes: You must be at least 10m close to Alt-Zoom position (llRezObject() limitation) // There's no "clamping code" included to cut the rays to be inside of a region // // Creator: Teleworm Gelber //
default {
state_entry() { if (llGetAttached() > 0) { llRequestPermissions(llGetOwner(), PERMISSION_TRACK_CAMERA); } else { llOwnerSay("Attach me as a HUD"); } }
run_time_permissions(integer permissions) { llOwnerSay("Alt-Zoom on any curved surface in the region and then click me to get the Alt-Zoom cursor coordinates and an Object will be rezed there"); }
touch_start(integer total_number) { vector camPos; // camera position rotation camRot; // camera rotation
vector rayEnd; // ray end vector
vector curPos; // Alt-Zoom cursor position rotation curRot; // Point on a surface rotation (Z-axis = SurfaceNormal, X-axis = line of sight)
vector fwd; // surface Forward vector vector left; // surface Left vector vector normal; // surface Normal vector
list rayData; // ray cast return data
if ((llGetPermissions() & PERMISSION_TRACK_CAMERA) != 0) { // getting camera location camPos = llGetCameraPos(); camRot = llGetCameraRot();
// Cast a ray in a line of your sight (10.0 means llRezObject() limitation) rayEnd = camPos + 10.0 * llRot2Fwd(camRot);
rayData = llCastRay(camPos, rayEnd, 0, RC_GET_NORMAL);
if (llList2Integer(rayData, -1) > 0) // check status code { // get the Alt-Zoom cursor position and orentation curPos = llList2Vector(rayData, 1); normal = llList2Vector(rayData, 2);
// calculate axis for point oirentation left = llVecNorm(normal % llRot2Fwd(camRot)); fwd = left % normal; curRot = llAxes2Rot(fwd, left, normal);
llOwnerSay("Alt-Zoom Position: " + (string) curPos); llOwnerSay("Point Rotation: " + (string) curRot);
// rez an Object on a top of hit surface, 0.25 means the prim center offset from surface (0.5m cube) llRezObject("Object", curPos + <0.0, 0.0, 0.25> * curRot, ZERO_VECTOR, curRot, 0); } else { llOwnerSay("Nothing hit, try again"); } } else { llOwnerSay("Attach me as a HUD first"); } } on_rez(integer par) { llResetScript(); }
}</lsl>
--Teleworm Gelber 23:08, 6 July 2010 (UTC)
Inaccurate (buggy) position and normal
I don't really have time for this, ... but I tried it out with a quick script (see below) and my conclusion is that the place that is reported for the hit is very inaccurate at times. It certainly isn't equal to the physical (collision) shape of objects, for example the place another physical object would lay, or where you'd stand if you stood on top of a prim with your avatar, and often it's just near random (actually, this is clearly a bug).
The script that I used in my objects is:
<lsl> vector center; float distance = 15.0;
rez_marker(vector pos, vector normal) {
llRezObject("Marker", pos, ZERO_VECTOR, llRotBetween(<0,0,1>, normal), 0);
}
probe(vector direction) {
//llSay(0, "direction = " + (string)direction); vector start = center + llVecNorm(direction) * distance; list results = llCastRay(start, center, RC_REJECT_AGENTS|RC_REJECT_PHYSICAL|RC_REJECT_LAND, RC_GET_NORMAL); if (llList2Integer(results, -1) > 0) { //llSay(0, "llCastRay returned " + (string)results); vector pos = llList2Vector(results, 1); vector normal = llList2Vector(results, 2); rez_marker(pos, normal); } else { llSay(0, "llCastRay FAILED!"); } //rez_marker(start);
}
init() { }
default {
state_entry() { init(); }
on_rez(integer param) { init(); } touch_start(integer total_number) { if (llDetectedKey(0) != llGetOwner()) return;
center = llGetPos(); vector direction = <1,0,0>; float alpha; for (alpha = 0.0; alpha < 360.0; alpha += 10) { vector eul = <0, 0, alpha * DEG_TO_RAD>; rotation quad = llEuler2Rot(eul); probe(direction * quad); } }
} </lsl>
Put it in an object together with an object named "Marker". The Marker object should be a (red) sphere of size 0.1 x 0.1 x 0.01.
The script will rez the Marker object on the surface of the object you put it in, with it's flat side outwards. If you test this with a cube of 10x10x10 you'll understand what is the idea :p.
Next test it with a Cylinder of size 3.4 x 4 x 3.342 Taper X and Y both 1.00, Top Shear X = 0.30, and Y = 0.0 (the rest default)... and see the deviations.
Try many more funny shaped objects to see loads and loads of bugs and inaccuracies.
--Aleric Inglewood 0:55, 7 July 2010 (UTC)
You know, part of me hopes you're right--and that there's nothing I can do about it. Shapes like you're describing are terrible for the physics engine (tons of triangles, some of the degenerate, etc.). That said, I'll take a look at the physics debugger we have and see what's going on tomorrow. I suspect that the physics representation just isn't quite what you think it is. We'll see. Either way, thanks for bringing it to my attention.
Falcon Linden 03:41, 7 July 2010 (UTC)
- As Teleworm points out below, the problem here is in your script, not in the llCastRay. You should check the hit list to find the hit with the UUID matching the scripted object's key and use that. You may still get more than one hit if you're near the edge of a triangle or if your shape is not convex, however.
- Falcon Linden 04:07, 8 July 2010 (UTC)
Simple Raytracer
I did this a few days ago, it's pretty nifty!
--Moy Loon
Not just nifty, bloody awesome! Btw, notice the way the two thin cylinders show as boxes. We replace long, thin cylinders with boxes. Can you take a photo with an avatar? :) Falcon Linden 04:09, 8 July 2010 (UTC)
Visualizing rays for debugging?
Would it be possible to have the server send to the client the exact position of the begin and end points of the ray (so the client can render the ray itself) to help with debugging? (like trying to figure out ray positioning for a complex shaped linkset that needs close rays) I imagine it would be somthing like, the client tells the server it wants the rays, then the server will send the info for all rays owned by the avatar, and the client will render them as beacon like lines that fade gradually (the fading time would be a debug setting), perhaps add a bit of animation tot he beam like those pulses for the "cheesy beacon" for TP targets and tracking people on the map, to indicate the direction of the ray. To cope with packet loss, each time the client receives ray data it will tell the server whether to continue or stop, or perhaps just keep sending the request every N seconds and if the server don't get a request for a few N seconds it stops sending the info to that client. --TigroSpottystripes Katsu 16:59, 7 July 2010 (UTC)
- I wish. Sorry, that's out of the scope of this project (which is intended to require a minimum amount of development time. So far, I think I've spent <10hrs coding it, and I'm trying to keep it under 20 total.
- Falcon Linden 04:20, 8 July 2010 (UTC)
You could also just rez an object to 'visualize' it, learn about llRotBetween, and how to split things up into 10m chunks! --moyloon
Edge of sim returning usefull results
How about if when the ray hits the edge of the sim, position will be the intersection of the ray with the edge (since it can't go past it), and the UUID will be one constant if there is another sim on the other side of the edge, and another constant if it leads into the void? --TigroSpottystripes Katsu 20:02, 7 July 2010 (UTC)
Sorry, that's just a little too hacky and out of scope for this one. :) Would be interesting, though! Feel free to submit a jira for interrogating the region as to its neighboring sims. That might be a useful function. Falcon Linden 04:11, 8 July 2010 (UTC)
- I think this is a fairly important case to include, and Tigro's suggestion seems reasonable, as the function can at least return NULL_KEY for any collision with the sim-boundary, since no object can have
NULL_KEY
as a UUID, it also identifies a form of valid collision (collided with sim-boundary). It doesn't really make sense for the scripter to have to check this themselves, specifically for objects that are tracing lines relative to themselves such as AI objects. - The whole inability of rays to cross region boundaries is turning out to be a massive headache that means rays are unsuitable for nearly all serious combat systems, we may as well have a way to handle it as simply as possible so that some ways around it can be designed. For example; a weapon could perform a ray-cast, but if the last result is
NULL_KEY
then it will immediately fire a traditional projectile instead, cutting down on most normal projectile use, but using them in situations where they are still better.
-- Haravikk (talk|contribs) 02:43, 8 September 2011 (PDT)
Phantom getting hit?
Could anyone confirm if phantom objects are really not being ignored please? --TigroSpottystripes Katsu 23:18, 7 July 2010 (UTC)
Yes, this is a bug that I will fix when I have time. Shouldn't be too hard. Falcon Linden 04:11, 8 July 2010 (UTC)
- Even flexies are getting hit, but the the normals seem to be messed up (in my preliminary tests it seems the normals returned for flexies all point up regardless of where you hit them) --TigroSpottystripes Katsu 05:29, 8 July 2010 (UTC)
- Flexies attached to phys linksets seem to be harder to hit (they also got a funky collision but just with the ground apparently, nothing but lucky rays and the ground seems to collide with them, i'm not 100% sure, but i think in H4 not even the ground touches physical flexies) --TigroSpottystripes Katsu 05:44, 8 July 2010 (UTC)
Not hugely surprising, if phantom is getting picked up. Flexies don't have a flexible physics rep, I think it's just a box or something. I'll have to look into it, but probably not before next week. Curious, though, what about trees? (Note that a tree's physics shape is a very narrow box, so you'd have to cast right in the middle of the tree.)
Falcon Linden 05:36, 8 July 2010 (UTC)
Haha, whoops. I looked at my code and it's a one line bug. I could fix it now, but it's not critical and it wouldn't get updated on Aditi for a few days anyway. But rest assured, it should be a quick and easy one. :) Falcon Linden 05:49, 8 July 2010 (UTC)
- Would it be possible to add a checkbox or a setting that scripts can set to keep flexies colliding with the ground when desired? I've jsut made a random toy that it's kinda fun to watch that without flexies colliding with ground but nothing else wouldn't work quite the same (i'm asking for a somthign liek a checkbox/hidden switch because i can imagine that if this behavior isn't present in H4 some stuff might break if it's kept). No biggie if it has to be fixed though. --TigroSpottystripes Katsu 07:04, 8 July 2010 (UTC)
- This reminds me of one existing (Agni) edge case that might be useful to clear up with this. Currently if an avatar sits on an object, and that object then sets VolumeDetect to TRUE, the physics engine sets the avatar to phantom, and it does not register any hits on the avatar, even to the point of rendering the avatar invulnerable with regards to LL Damage. I had not thought to test this with RayCasting, but I am wondering what the intended effect will be in terms of how rays will interact with these phantom avatars. For additional information, see SVC-1253 which has sort of lingered in limbo, probably because there are more important things to fix. However, if the raycasting code is still being written, it'd be nice to prevent this sort of unintended behavior before it even begins.
- Jahar Aabye 03:27, 9 July 2010 (UTC)
- The sitting-phantom glitch with llVolumeDetect already has some odd behaviors, if you enable physics on the linkset. When physical, the avatars behave something like tiny points of solid material, snagging on objects that the linkset passes through. It's very odd. I suppose I should bring some example code around and shoot rays at it, an' see what happens?
- --Michelle Resistance 16:19, 13 July 2010 (UTC)
Some good news for llCastRay
I was playing with the script from Aleric Inglewood and tried to figure out what causes this strange inaccurate positions and normals. And I figured out that the main reason is the Marker size and shape and not the physic engine.
In the example of Cylinder of size 3.4 x 4 x 3.342, the ray hits a Marker which was previously rezed one step before and not the surface of the cylinder. That is the reason, why were Normals wrong oriented. I modify the script in such a way that I numbered all Markers with llSetText.
The second problem is inaccurate position. A marker is always placed about 3-5 cm above a surface, and not exactly on it on a flat surface. This can be seen on a cube object. On a sphere, this error is smaller. And in a shape of this deformed cylinder sometimes markers appears below surface and becomes invisible, but never more than 5cm.
To correct the Aleric experiment, just make a smaller marker. And when all markers are rezed, resize the cylinder to become little smaller to see all markers. If you zoom with your camera very close, you can see that all markers follow the orientation of polygones that define the object shape.
--Teleworm Gelber 23:40, 7 July 2010 (UTC)
Good catch. I came to the same conclusion about Aleric's script, but I cheated (I have a way of visualizing the raycasts and the whole physics scene :).
As for the inaccurate position, it's not inaccurate per se. It's just not what you expect. Most shapes in the physics engine (anything that isn't a perfect cylinder or perfect sphere, as I recall) has an additional radius of 5 or 10cm (I can never remember which). This is why if you stack physical boxes they'll have a gap between them. We use raycasts for sitting, but we specifically account for the radius in that code and in a few other places (like foot IK). There are a few other idiosyncracies around raycast results. For example, for most shape a ray parallel to its surface will not return a hit, nor will a ray terminating exactly at its surface or a ray originating inside the shape (unless it's a concave shape made of triangles, in which case the same holds true, but it's the individual triangle the ray begins inside that won't be hit).
Falcon Linden 04:18, 8 July 2010 (UTC)
The 10cm difference can be a problem for a system I have been working on for a long time now. With a lot of collision detection and Avatar Sensors, I have a system that causes the Avatar to behave differently physics-wise when stepping onto certain named surfaces. Currently, the problem is the collision detection system is unreliable when objects are real close together. It detects one or the other, and there is no way to determine which the avatar is standing on. I am hoping llCastRay is better, but it still leaves problems because of the invisible "extra height" of every prim. If a prim is underground, but only slightly, collision still detects the underground prim, despite the avatar only colliding with the actual ground. This occurs up to 1/4 a meter distance between the two vertically. If llCastRay has the same problem, there will still be too many workarounds to fix it. With that said, llCastRay is still something I wish to see completed. It's imperative for reducing sim lag, since llCastRay can take the place of 3 or 4 functions (one a repeating sensor event) in my script, and probably in many other scripter's scripts as well.
Da Chrome 16:47, 3 May 2011 (UTC)
Can we have this on the maingrid pretty please?
I know this is experimental etc, but would it be possible to port the ray code to a sim version avaible on the maingrid and offer a sandbox sim with this hybrid version so we can play with ray with our main invs, live groups, chatting with friends inworld etc? --TigroSpottystripes Katsu 00:19, 8 July 2010 (UTC)
Sorry, no. We're not set up for doing that sort of thing. We can bring your agni inventory over to Aditi (contact Oskar), but you'll lose anything you currently have on Aditi. Falcon Linden 04:21, 8 July 2010 (UTC)
- I know, the beta grid inventory is one way copy of the main grid inv, everything gets overwritten when it's refreshed; i would rather not have to keep exporting the stuff i make there when i want to keep them though. --TigroSpottystripes Katsu 07:09, 8 July 2010 (UTC)
Just saying TY
TY ;-) Will be cool. Keep it up Falcon.
just letting you know
I'll be out of town this week, won't be able to read the stuff here nor log in to test stuff, cya. --TigroSpottystripes Katsu 20:57, 10 July 2010 (UTC)
Cast Ray vs. Ray Cast
The function name proposed is "llCastRay" but the constants start "RC" as in "Ray Cast". Would make sense to have them be consistent (as in "CR"). It's annoying keeping llMessageLinked and link_message straight. -- Strife (talk|contribs) 16:40, 15 July 2010 (UTC)
- I second that motion. I'm hoping this functionality is introduced and however it comes will be better than not coming at all but, while the opportunity exists to craft it to be as clean and user friendly as possible, that opportunity should be taken. Although this seems like a tiny issue (link_message vs llMessageLinked OR llSetLinkPrimitiveParamsFast *fingers gasp for breath* (although at least it wasn't llSetLinkPrimitiveParametersFast)) there is no good argument in favor of making function or event names insensible whereas there are good arguments in favor of them being simple and easy to write and remember. Now is the time to get that right. Still hugely in favor of the functionality though so if you MUST call it something complex and irritating, go right ahead ;-) -- Fred Gandt (talk|contribs) 07:13, 17 July 2010 (UTC)
Hey guys,
The logic is that the method, llCastRay, is a verb phrase ("cast a ray"), whereas the parameters are noun/adjective phrases ("Ray Cast Reject Agents", "Ray Cast Reject Terrain"). Does that make sense to you? Falcon Linden 06:39, 19 July 2010 (UTC)
- Hey Falcon :-)
- Grammatically correct it may be but, fiddly. Muscle memory etc. llCastRay(CR_summit_summit) just flows better. It's really only the _summit_summit that matters at the end of the day. If there were flags that were BOTH RC_ AND CR_ (depending on grammatical doobrywotsits) then cool; but, if there will only be EITHER CR_ OR RC_ I for one would prefer to go along with the CR_ simply so I don't need to think about my old English teachers in the middle of writing a statement. *not terribly concerned but, interested* -- Fred Gandt (talk|contribs) 10:35, 19 July 2010 (UTC)
- I like the gramaticly correct approach, saves time when reading a script, and once you get used to it it flows as smoothly as anything else. It somtimes brings a smile to my face when i realise what i'm writting makes sense even if i didn't understand what the words make happen under the hood. And the more consistent LSL is the better, it already goes the gramaticly correct route elsewhere, so it would be expected it would also do it here. --TigroSpottystripes Katsu 20:48, 19 July 2010 (UTC)
- Tigro...An example of LSL being grammatically correct elsewhere would be, what? Perhaps the well known functions llGiveFolderOfInventoryListed or llSendMessageToLinkInSet?
- Falcon (since I'm already here)...I was thinking that since the world at large (when thinking about ray-casting) thinks of Ray-Casting rather than Casting-Rays it would prolly be even simpler to name the function llRayCast. *shrugs* TBH, whatever the parts end up being called it's how they work that matters most. Awesome of you to be trying to get this out. Hear's (now) quietly hoping. -- Fred Gandt (talk|contribs) 04:02, 20 July 2010 (UTC)
- llMessageLinked isn't gramaticly correct?
- Falcon (since I'm already here)...I was thinking that since the world at large (when thinking about ray-casting) thinks of Ray-Casting rather than Casting-Rays it would prolly be even simpler to name the function llRayCast. *shrugs* TBH, whatever the parts end up being called it's how they work that matters most. Awesome of you to be trying to get this out. Hear's (now) quietly hoping. -- Fred Gandt (talk|contribs) 04:02, 20 July 2010 (UTC)
- Tigro...An example of LSL being grammatically correct elsewhere would be, what? Perhaps the well known functions llGiveFolderOfInventoryListed or llSendMessageToLinkInSet?
ray_impact event vs. http
I've been thinking about the asserted need for a ray_impact event to determine if you've been hit by a raycast. Babbage suggested that instead of creating a new ray_impact event (which is trickier than any of us might like), the same goals could be accomplished using the existing HTTP url system. The idea was that you'd set up a system as follows for securely communicating the results of the ray cast:
1) Users wear a hit detection script that acquires an HTTP-in URL and stores it in its description. 2) For weapons builders, you provide a copy, no-mod (and thus unreadable) script (call it a "firing script") that has a link_message event that the weapon builders' scripts can use to talk to it. This script also contains a secret key known to the hit detection scripts. 3) The weapon script sends a link message to the firing script with the requested start/end position of the ray. The firing script (which is secure because it was written by the system creator) then casts a ray (if the start/end points are allowed based on game rules). If it detects a hit, it gets the target's hit detection url from the target's description and sends an HTTP POST with the details, including a secret code to verify authenticity.
What would prevent this from being a viable alternative to a ray_impact event? (Obviously, it generalizes to other uses equally well.) If you think it will be too slow or have another fault, could you code up a simple, testable example?
Thanks!
- Something similar could be done using llRegionSay by sending the message on a frequently changing, random channel. The synchronization on channel would be performed by llRegionSay'ing a new random channel number periodically, with the number encrypted using a key shared by all interested/authorized scripts. This would seem a lot simpler/faster than the HTTP idea.
- I think a ray_impact would be a useful event, but by no means necessary. There's any number of ways to securely communicate script to script using chat, http, reading one another's descriptions, carrier pigeon, etc., with llSHA1String or llMD5String and a password providing authentication. If ray_impact is any trouble, drop the idea; don't let it stand in the way of getting us llCastRay. It would be simpler to update existing combat meters using a new event, I think, but I don't think that should be a barrier. Jack Abraham 07:23, 22 July 2010 (UTC)
Change Reject constants to be inclusive
Many, if not all other, LL calls use constants OR'd together in a positive sense to change a scripts' behavior. This is the only function where I have seen constants used to reduce what the function does.
I'd suggest changing the RC_REJECT constants by eliminating the _REJECT_ portion and also adding a new constant, something along the lines of RC_ALL.
A "normal" call would have the ALL constant unless you only wanted a subset of actions, in which case your OR together the constants you need.
What do people think? Jonathan Yap 10:01am, 24 July 2010 (UTC)
- Although unusual (this is just my opinion) rejection rather than inclusion seems like a perfectly reasonable way around things. I wonder if it might be more efficient too. Analogy: Compact discs: When a CD has bonus tracks that are often disruptive when listening to an otherwise complete listening experience, it is typical to avoid being disturbed after the album is finished that we need to include all the album tracks in a programmed playlist before starting the playback. I have often wished that I could exclude the few bonus tracks instead. I would go so far as suggesting that bonus tracks should be (in what seems an illogical fashion) the first tracks indexed on the CD so that no playlist programming is required at all; We simply start playback at track 4 to avoid playing the 3 bonus tracks. So although unusual and unexpected, an alternative way might be more efficient and simpler to use.
- This however is not a compact disc so, my greatest concern is with how well it works and how efficient it is as code. If there is NO difference in efficiency at all between rejection and inclusion, for the sake of continuity I would certainly agree with Jonathan insofar that the normal way to construct a function by inclusive constants would be preferable. -- Fred Gandt (talk|contribs) 08:26, 25 July 2010 (UTC)
- I agree with Jonathan and Fred on this, as there is always the possibility that llCastRay may detect new types in future, and by building an exclusive filter you may suddenly start detecting objects you don't expect to as a result. It is much better for the function to simply return what you ask for, rather than returning everything you ask not to return, as it is a much more tightly controlled result that way.
-- Haravikk (talk|contribs) 11:09, 22 October 2010 (UTC)
- I agree with Jonathan and Fred on this, as there is always the possibility that llCastRay may detect new types in future, and by building an exclusive filter you may suddenly start detecting objects you don't expect to as a result. It is much better for the function to simply return what you ask for, rather than returning everything you ask not to return, as it is a much more tightly controlled result that way.
- This however is not a compact disc so, my greatest concern is with how well it works and how efficient it is as code. If there is NO difference in efficiency at all between rejection and inclusion, for the sake of continuity I would certainly agree with Jonathan insofar that the normal way to construct a function by inclusive constants would be preferable. -- Fred Gandt (talk|contribs) 08:26, 25 July 2010 (UTC)
Optimizing Simulations
Well, I got quite a few ideas that surround this issue, and I have tried to narrow it doesn't to a simple concept that describes a pattern how to use functionality, like llCastRay(), to optimization simulations. I blogged more details here: Icesphere Blog. Let's not confuse this with a common ray-tracer. I want the client end to contact a prim on the simulator to demonstrate the basic pattern. The prim just needs to cast rays and send data back to the client. The client-side fills in the details. This first phase would only need to get a rough scene layout. Close objects probably can be gathered with a scanner and some further objects can be done with llCastRay() (can't cross sims yet, but someday maybe). Hopefully, use http client/server methods to communicate with detected objects.
Now with that basics above, scripts added into detected objects could further describe details of the scene through client/server methods. I've seen other LSL raytracers, that didn't use llCastRay(), that used scripts to store "material" data and thought... cool!
Posted some vulgar code here: User:Dzonatas_Sol/HttpCastRayLLSD Dzonatas Sol 05:52, 28 July 2010 (UTC)
Possibility of a "Fast" trace
Hi Falcon.
ty ty ty ty ty ty :D (Now that I got that off my chest :p)
I've got a bit of a suggestion, is it possible to add a llCastRayFast which only determines if there is something within the filter that's in the way between point A and point B.
E.g. xyz avatar wants to go to sleep but a requirement to goto sleep in a hud is that the avatar is sheltered from the elements, the script does a trace looking to see if the avatar has a clear shot at the sky or not, if not the avatar is under cover.
I really hope the hands of god (LL) allow this to make it into the maingrid.
Look forward to catching you on the test grid :)
Cheers, Lastro
edit: Also see my user page for some code I've done, which works how I would expect it to (appart from it detecting the target object)
Another idea would be the ability to do a ray trace between two object/agent/etc UUIDs. --Lastro Greenwood 00:54, 7 August 2010 (UTC)
Any updates?
I haven't been around much, any news regarding this? Falcon hasn't been sacked too, has he? o.o --TigroSpottystripes Katsu 20:26, 26 September 2010 (UTC)
- Hi, Falcon is still among the living Lindens but he is working on other projects like mesh. llCastRay is "shelved until further notice, unfortunately." --Cerise Sorbet 23:17, 26 September 2010 (UTC)
- IMO this should be given more priority than mesh import. --TigroSpottystripes Katsu 00:12, 27 September 2010 (UTC)
- Well Mesh import is a big important project so I wouldn't say that. But it's odd that the scripting team can't be working on it, as efficient scripts and script limits are their domain, and that seems to be the main hold-up on the function right now. Given the huge, complex workarounds to create scripted AI without this function it certainly comes under script efficiency, as I have pathing objects that use four or five scripts to give some semblance of accuracy, when this single function would eliminate all of them.
-- Haravikk (talk|contribs) 11:23, 22 October 2010 (UTC)
- Well Mesh import is a big important project so I wouldn't say that. But it's odd that the scripting team can't be working on it, as efficient scripts and script limits are their domain, and that seems to be the main hold-up on the function right now. Given the huge, complex workarounds to create scripted AI without this function it certainly comes under script efficiency, as I have pathing objects that use four or five scripts to give some semblance of accuracy, when this single function would eliminate all of them.
- IMO this should be given more priority than mesh import. --TigroSpottystripes Katsu 00:12, 27 September 2010 (UTC)
Redesign of llCastRay()?
I'm curious as to why this function requires a start and end point rather than describing a true ray like so: <lsl>list llCastRay(vector origin, vector direction, float range, list options);</lsl>
Quite simply the two vectors should describe the origin point (start) and direction of the ray, it's then up to the function to decide whether to process until range
is reached, or if a region boundary is hit (whichever occurs first). A range of 0.0 would describe an infinite ray, in which case it will only stop upon hitting the maximum number of unfiltered objects, or a region boundary. Preferably the ray should continue a short-distance into the next region rather than halting immediately upon a boundary, the standard overlap is around 20m I believe?
-- Haravikk (talk|contribs) 11:06, 22 October 2010 (UTC)
list castray(vector origin, vector normal, float distance, list options){ return llCastRay(origin,origin+normal*distance,list options); }
It's easier in my opinion, to have a start and stop, instead of start, normal, and distance, aswell as I'm sure most other people would think the same way, But, that's a wrapper for how you'd want it.
--Moy Loon 17:50, 22 October 2010 (UTC)
- Problem is that it lacks a way to properly describe infinity. I suppose if we know that the ray can't go beyond the region then a range of 16536.0 or some other large value is fine, but it seems a lot simpler to be able to use the normal/direction vector. I mean you could even simplify it further by removing the origin point and assuming the ray is always cast from the scripted prim's centre, though an origin may be especially useful. It's just that with the normal you could do the following:
<lsl>// What can I see? llCastRay(llGetPos(), llRot2Fwd(llGetRot()), 50.0, []);</lsl> This seems a simple, and likely very common use-case of the function. Likewise it may be desirable to have the filter as a formal part of the function, rather than under options, and just use the same constants, so that I could more specifically do: <lsl>// Who can I see? llCastRay(llGetPos(), llRot2Fwd(llGetRot()), 50.0, AGENT, []);</lsl> Or possibly even do the same with the maximum number of values returned, as the filter and the maximum are the two that are needed most, list-based options should be restricted to things that are additional, rather than fundamental to typical usage of the function. But in any event, to me this seems a lot simpler, as other you have to do: <lsl>// Who can I see? vector pos = llGetPos(); llCastRay(pos, pos + (llRot2Fwd(llGetRot()) * 50.0), [RC_REJECT_TYPES, RC_REJECT_PHYSICAL | RC_REJECT_NONPHYSICAL | RC_REJECT_LAND]);</lsl>
Hell, the whole set-up of the function is a bit bewildering, I've posted a function that I believe would be a lot cleaner/more-usable and consistent, and you can find it here.
-- Haravikk (talk|contribs) 12:17, 23 October 2010 (UTC)
- What I really love is how the Lindens working on this function seem to just love ignoring all the issues I've been trying to raise with the design of it. Now we're just rushing towards releasing a function that barely resembles an LSL call, and does just about everything it needs to backwards. With no true control over the output this function is pretty much useless for any of the cases I'd want to use it for, as I'll need to do complex list manipulation in order to sort the results. Does no-one but me care that this function seems like a bad joke? It has all the functionality we need, and have wanted since day one of scripting in SL, and yet delivered in a package that makes no sense in the slightest.
-- Haravikk (talk|contribs) 04:54, 6 July 2011 (PDT)
llCastRay for Vehicle's wheels suspension?
I'm still disturbed from the day you suggested it, Falcon. While llCastRay itself is a great idea, but it bear no good logical use for vehicle suspensions system. You know I didn't have to hesitate to say no, I knew right off the bat that it was a bad idea.
There are ways to track height of on-coming prims and land slope to clench its wheels in a single frame before collision happens. This is requiring to scan the path at every physic frames and more. You also need to make calculation how deep the "bump" is and throw suspension's reaction force up the car as a jump or "damping" shock. However... llCastRay can not help with physic collision when the wheels are trying to push outward to raise the car up. Moving wheels via llSetLinkPrimParam (or the fast version as well) would clip through solid object within the first few physic frames, later Havok engine try to resolve by pushing out the wheel, some times result in getting stuck into the ground or objects it drives on top of. It happens on a tiny smooth bump, causing a dramatic physic motion interruption, even come to a full stop without being fully stuck into the road. I've had done this similar setup with collision event and sensor. I spent two years researching a better way to handle vehicle suspension with all the LSL code and complex physic algorithms I could use.
Vehicle suspension system need much more to work with, but it would be pretty darn silly to let Havok's vehicle library go to waste without any script's delaying the collision event in frames between. My bigger concern is having Linden Lab (or you, Falcon, for that matter) use llCastRay as a "work around" excuse not to provide better suspension/motorized system. I'm not demanding to give us Havok's suspension system right at this minute, but be aware how poorly dealt it has been.
Keep up the good work; I'm sure I'll find more uses for llCastRay. -- ₪ 23:19, 11 February 2011 (PST)
- I don't think he meant wheels with suspension, but solid wheels that work realisticly, only proving thrust when in contact with the ground (or anything else) --TigroSpottystripes Katsu 12:46, 6 May 2011 (PDT)
Simplification function for use.
<lsl> list ray(vector s, vector e) {
return llCastRay(s,e, [ RC_REJECT_TYPES, 0 //RC_REJECT_AGENTS //|RC_REJECT_PHYSICAL //|RC_REJECT_NONPHYSICAL //|RC_REJECT_LAND , RC_DATA_FLAGS, 0 //RC_GET_NORMAL //|RC_GET_ROOT_KEY //|RC_GET_LINK_NUM , RC_MAX_HITS, 1, RC_DETECT_PHANTOM,FALSE ]);
} </lsl> Draconis Neurocam 10:19, 8 April 2011 (PDT)
Where can i find a list of sims currently aware of this command?
I've been away for some time, trying to come back now, but the Oatmeals that used to recognize the commands aren't doing it anymore, where can i find an updated list of sims where i can play with llCastRay right now? --TigroSpottystripes Katsu 12:43, 6 May 2011 (PDT)
the mesh sims on betagrid seem to support it well --Vagabond Carter 16:47, 2 July 2011 (PDT)
making use of the normal
after some experimentation on betagrid I've found the following handy:
to turn a normal into a rotation (for rezzing portals/decals etc) vector norm = (the normal retunrd by llCastRay() ); rotation hitrot = llRotBetween(ZERO_ROTATION , norm);
--Vagabond Carter 16:15, 2 July 2011 (PDT)
Pre-Release?
Shouldn't the document be tagged with "|mode=pre-release"? Considering the fact that it's not currently "activated"?
--Ayamo Nozaki 12:21, 7 September 2011 (PDT)
Ray cast for creating an in-world display
In my recent edit I removed the mention under ideas for uses of creating an in-world display object. My reason for doing so is that this simply isn't possible to do with ray-cast, as the ray-cast doesn't return a colour, and you cannot query face-colours for arbitrary objects, and cannot gain colour information for textures. Therefore, to do this in LSL only you would need a script in every single object that you might possibly collide with, and hard-coded colour values for every texture (potentially every texture co-ordinate) in order to get any useful colour from them. The alternative would be to use a bot, however the bot itself wouldn't benefit at all from the addition of llCastRay, as it can simply perform true visual ray-casting instead, which would return a far more accurate result, more efficiently.
Sorry, it just isn't the right type of ray for that particular application!
-- Haravikk (talk|contribs) 13:40, 7 September 2011 (PDT)
- Seems arbritary. Just because you lack any ideas to improvise in the situation doesn't mean others won't. It's not absolutely essential to have knowledge of textures and colours of every pixel in the world to make a decent render. See the renders above on this page by Moy Loon. It is true that is a bit of a novelty toy but still a vital example of applying raycasts for a potential purpose, as this sort of thing is usually otherwise impossible without involving external programs, such as bots and custom clients. Finding example uses for raycasts is extremely vital for imploring scripters to find creative ways to use it. Raycasts are extremely cool devices for gaining knowledge of an environment for really interesting uses. It's important we list here what real examples we know of. Otherwise people will think its' only use is for shooting bullets in FPS shooters. --Nexii Malthus 21:14, 7 September 2011 (PDT)
- If they'd care to post a description of how it's done then maybe there is something I've completely missed, but the rays involved are ones within the physics engine, and the simulator has almost no actual knowledge of the visual information represented within a scene, and like I say it's currently impossible for a ray-casting object to acquire colour information for every object that its rays collide with, not without those objects being known and prepared beforehand (either containing scripts, or named in such a way as to describe their visual properties, e.g - reflective, red, etc.), or using a bot (which can do the whole thing without llCastRay anyway, and a lot more effectively). I've been scripting in LSL for a long time now, and while llCastRay() allows us to grab objects more easily, it doesn't add any new capabilities that make visual ray-casting any easier in practise, except perhaps visual distance, it's still no easier to get actual visual information from it though.
- Visual distance is certainly useful for AI effects, as you can use a ray-cast for finding out which object is actually visibly closest, but that's already noted. I simply can't find a single way that this feature can allow visual ray-tracing as anything other than a novelty for prepared scenes, that can just as easily use a static image, since you can't ray-trace arbitrary objects, for example if an avatar popped into the scene. If we want to create useful images of in-world items, then bots taking screenshots, or performing the ray-tracing without LSL scripts, are the best methods, if it's a sought-after feature then really we need something more feasible, like exposing the mechanism that sims use to generate their map-tiles, such that we can use it to take scripted snapshots. As far as examples go, we may as well have llSensor() encouraging scripters to use sensors to map out the location of every avatar in-world; it's do-able, but one of the last things anyone should be doing with that feature.
-- Haravikk (talk|contribs) 02:35, 8 September 2011 (PDT)
- Visual distance is certainly useful for AI effects, as you can use a ray-cast for finding out which object is actually visibly closest, but that's already noted. I simply can't find a single way that this feature can allow visual ray-tracing as anything other than a novelty for prepared scenes, that can just as easily use a static image, since you can't ray-trace arbitrary objects, for example if an avatar popped into the scene. If we want to create useful images of in-world items, then bots taking screenshots, or performing the ray-tracing without LSL scripts, are the best methods, if it's a sought-after feature then really we need something more feasible, like exposing the mechanism that sims use to generate their map-tiles, such that we can use it to take scripted snapshots. As far as examples go, we may as well have llSensor() encouraging scripters to use sensors to map out the location of every avatar in-world; it's do-able, but one of the last things anyone should be doing with that feature.
Ray-Casting Across Region Boundaries
Okay, so I've been trying to come up with a good mechanism for ray-casting across region boundaries. I don't think it's actually too hard, but it will require a simulator combat system which performs the actual ray-casting, on behalf of the weapons. This isn't a bad thing actually, as it can be used to provide additional features to prevent abusive weapons. Basically the set-up is something like:
- Each simulator will have an object in at least one of its corner, next to a corresponding object in each neighbouring sim. So for a grid of 9-sims (3 x 3), the central sim would have an object in each corner, the side sims would have two objects each in each corner on the side neighbouring the central sim, and the corner sims will have one object in the corner closest to the central sim.
- These objects will open private chat-channels with one another, using whisper or say (or target say if it works on region-edges?). They will also open a global listen on a standard channel for the combat system.
- When an avatar fires a weapon, the weapon will communicate on the standard channel a description of its ray, using region say.
- The objects within the simulator will hear this message (ideally, if a sim contains multiple objects, all but the nearest will discard the message for performance).
- The object responding to the message will trace the portion of the line that lies within the simulator.
- If a result is returned, then the attack is resolved.
- If no results are returned, then the attack is passed on to any neighbouring sim in the correct direction, using the appropriate private channel to communicate across the sim-border.
- The neighbouring sim will then calculate a new line-segment, and test for any impacts within its region.
This mechanism can actually be much faster than any projectiles, as transmitting chat across region boundaries is a lot faster than transferring an object of any type. The main risk is when it comes to large-scale combat, as too much activity could lag the combat objects, though this is essentially no different from the current sources of lag, and should be lower overall anyway. Script limits would probably help with a lot of this (the impact of laggy avatars would be reduced).
However, this particular use of ray-casting actually favours the origin + normal + range method of describing the ray, as it can fully describe a line spanning multiple region, with only a single co-ordinate being re-calculated (which can be done trivially using the origin + (normal * range) method).
-- Haravikk (talk|contribs) 05:44, 16 September 2011 (PDT)
Controlled explosions
While reading SCR-203 it occurred to me that using this and llSetKeyframedAnimation you could mimic an object explosion without using physics, maybe. -- Strife (talk|contribs) 11:39, 20 September 2011 (PDT)
Imaging Examples
I've been experimenting with displays that create an image of objects and avatars in front of it, by casting rays from the position of each "pixel" on the display.
The first version had a resolution of 15 x 15 and used 226 prims. It calculated the distance from the start of the cast to the hit point, and used that to scale the color of each prim in grayscale.
The next version used prism type prims to have 5 faces per prim, like what the 10-character XYText uses, which allowed it to have a resolution of 35 x 35 and used 246 prims.
The next version displayed every prim in the scene with a unique color, based on its UUID, and the version after that scaled the color from lightest to darkest based on distance.
I tested the latest color version at a sandbox in order to combine 24 of them into an image with a resolution of 210 x 140, which used 5904 prims.
These images show the difference between standing and sitting using this method:
My next step is to send data gathered at a higher resolution to a webserver, and have it processed into a real image. After that, it should be easier to experiment with creating perspective (right now it's like a 2-dimensional mirror). I was able to get distance shading around an object with the later monochrome version, because it calculated the scale for each panel based on the longest hit for each panel (which also made the scaling vary wildly between panels).
It seemed like the only way to coordinate distance shading between multiple panels would be to have a separate object manage the panels with a complicated message system. So after I started with color, I based the scaling on a max distance of 256 so that all the panels would have the same distance shading. I think it might be possible to base an object's individual pixel shading on the minimum and maximum distance from the same object, after shading the whole object based on how far it is. I'll be able to try that as well, after success with the web processing. Eventually it should only require having a single prim rezzed in-world.
Sayrah Parx 08:09, 25 September 2011 (PDT)
- For depth, could you not simply assume a value at first, say 0m to 5,000m for consistency, since it shouldn't normally be possible to detect anything further away than this. This way, after you've cast all the required rays, all you need to do is take the min and max values and scale each pixel to the correct values using.
-- Haravikk (talk|contribs) 08:40, 25 September 2011 (PDT)
- The problem is that the min and max values are guaranteed to be different for each panel, unless every ray from every panel hits the same flat object and the object isn't rotated. I decided that it wasn't practical to worry about that, because even a single panel has 246 prims. So I'm glad that it works for a proof of concept, but the goal should be to remove the need for that many prims anyway.
- Sayrah Parx 21:40, 25 September 2011 (PDT)
This is 700 x 350 and took 10 hours and 17 minutes with a single scanner:
Sayrah Parx 20:18, 26 September 2011 (PDT)
Highlighting
I added the following to the bottom of the keywords.ini file under the appsettings folder inside the installation folder of the Phoenix viewer (i would expect it would work with other viewers pretty much just the same but i won't be testing) and now it highlights the stuff and got a hovertip explaining stuff and the keywords are present in the dropdown, i just copypasted from some of the text from the wiki page, and didn't really work much on it, it was just a small rushed job; the 3 numbers after "word" are the RGB color components of the highlighting, in the 0.0-1.0 range; seems you can even edit and save that file without closing the client and it will read the new values next time you open a script editor window, so it should be easy to tweak it to match whatever skin you are using.
#Raycasting stuff
#Command
[word .6, .0, 1.0]
llCastRay list llCastRay( vector start, vector end, list options );:Cast a ray from start to end and report collision data for intersections with objects Returns a list of strided values with an additional integer status_code on the end. Each stride consists of two mandatory values {key uuid, vector position} and possibly some optional values {integer link_number, vector normal} see RC_DATA_FLAGS for details. The status_code if it is negative is an error code, otherwise it is the number of hits (and strides) returned.
#CONSTANTS
[word 1.0, .3, 0.0]
RCERR_UNKNOWN The raycast failed for an unspecified reason. Please submit a bug report.
RCERR_SIM_PERF_LOW The raycast failed because simulator performance is low. Wait a while and then try again.:If possible reduce the scene complexity.
RCERR_CAST_TIME_EXCEEDED The raycast failed because the parcel or agent has exceeded the maximum time allowed for raycasting. \nThis resource pool is continually replenished, so waiting a few frames and retrying is likely to succeed.
RC_REJECT_TYPES Parameter: [ integer filter ] default [0]:Mask used to ignore specific types of objects (and avatars). filter is a bitwise-or combination of the following constants: RC_REJECT_AGENTS, RC_REJECT_PHYSICAL, RC_REJECT_NONPHYSICAL, and RC_REJECT_LAND
RC_DATA_FLAGS Parameter: [ integer flags ] default [0]:flags is a bitwise-or combination of: RC_GET_NORMAL, RC_GET_ROOT_KEY, and RC_GET_LINK_NUM. These select whether you want link numbers and hit normals in your results list. By default, you will get the UUID ('key') of the exact child prim hit. If instead you want the key of the root prim, set RC_GET_ROOT_KEY. A terrain hit will register as NULL_KEY
RC_MAX_HITS Parameter: [ integer max_hits ] default [1]:Maximum number of hits to return. Maximum value is 256. To avoid performance issues, keep it small.
RC_DETECT_PHANTOM Parameter: [ boolean detect_phantom ] [FALSE]:Set to TRUE (or nonzero) to detect phantom AND volume detect objects. It is not possible to detect only phantom objects or only volume detect objects. If set to TRUE, phantom and volume detect objects will always be detected, even if RC_REJECT_NONPHYSICAL and RC_REJECT_PHYSICAL are set in RC_REJECT_TYPES.
RC_REJECT_AGENTS
RC_REJECT_PHYSICAL
RC_REJECT_NONPHYSICAL
RC_REJECT_LAND
RC_GET_NORMAL
RC_GET_ROOT_KEY
RC_GET_LINK_NUM
--TigroSpottystripes Katsu 03:43, 2 October 2011 (PDT)
- Of course, backup the file before doing any changes jsut in case, i'm not responsible for any damages etc etc. --TigroSpottystripes Katsu 03:44, 2 October 2011 (PDT)
- Thanks for sharing this, I've been looking for a way to add the new things to Snowglobe for a while now. It works perfectly. I used .5, .1, .3 and .1, .1, .5 for the functions and constants respectively.
- Sayrah Parx 04:54, 2 October 2011 (PDT)