Jump to content

Ray Cast Help Request


BrownBoxStudio
 Share

You are about to reply to a thread that has been inactive for 3003 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Hi Guys!

I'm trying to learn about, and use, llcastray for a game. I see rays are quiet capable but the wiki seems a bit sparse compared to what I seen other programs shows is possible. I can setup the ray I want but the list options elude me. I'd like to get the uuid/key, or link number of a collided child prim but am not sure how. Also the point of collision but did not see any rules to do so. Is that possible?

To give some background I am finishing up a skeeball game. You shoot the ball by moving and rotating a child prim with arrow keys to throw the ball in the prims direction. I'm seeing about using raycast to setup another child prim to act as an aim line such as in the Wii Bowling image below. In Wii Bowling when the line collides with the edge of the lane the line shortens which is why I need the ray cast in the first place and the collision point, to set a proper line length when colliding with the skeeball lanes edge.

I don't usually ask for so much help but llcastray seems to be very capable but I can't find much information on it. Any help or suggestions are appreciated! Thanks ahead of time!

 



 

Also, a side note. When I have the program finished and mesh created I will be looking for some beta testers. Anyone interested? I would have some questions and in return you would get a copy of the final game, plus future updates, and one or two that can be shared with friends. If your interested, let me know. Thanks Again!

Link to comment
Share on other sites

If you are in mouselook, you know where the start of your cast ray is, at llGetCameraPos().  You want to cast it from that point to some spot that is directly ahead of that position but off in the distance. That position will be on a line that ends at llGetCameraPos() plus an offset that is corrected for your own rotation (or, rather, your camera's rotation).  So the llCastRay sequence that you put in your control event will have to look something like this:

 if(level & edge & (CONTROL_ML_LBUTTON | CONTROL_LBUTTON)) {      vector start = llGetCameraPos();      list results = llCastRay(start, start+<25.0,0.0,0.0>*llGetCameraRot(),[RC_REJECT_TYPES,RC_REJECT_PHYSICAL,RC_DETECT_PHANTOM,TRUE,RC_MAX_HITS,1]);      key TargetUUID = (key)llList2String(results,0);      vector TargetPos = (vector)llList2String(results,1);
}

In this case, I have elected to ignore hits with physical objects but include hits on phantom ones, just for illustration.  You would probably also want to ignore hits on avatars or the ground. The list results will include the UUID of whatever the cast ray detected within 25.0m, and its position.  And the LSL wiki tells you that "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."

 EDIT:  I just noticed that you also want the link number of the child prim that you hit.  You can get that as an element in the returned results list by specifying the RC_DATA_FLAGS value RC_GET_LINK_NUM.

Link to comment
Share on other sites

Well thanks for mentioning. If you noticed I am looking for beta testers so hopefully I can find out about effects like that. Though if it is a problem I'm not sure there is an alternative solution. Unless I can have one child prim detect collision with another child prim?  

 

Edit: Got a suggestion, in a script group, of doing some manual math to track the location and intersection so may have a better alternative to ray casting. I can track the prims corners and see if they go past the edge of the lane. 

Link to comment
Share on other sites


BrownBoxStudio wrote:

Thanks very much Rolig, helps me understand a bit better. Although I am still a confused on the list rules returning the information. How is item 0 of "results" the TargetUUID if the first list item is RC_REJECT_TYPES?
[ .... ]


The relevant note on the LSL wiki is perhaps a little hard to decipher smoothly:

"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."

In other words, you will always get the first two values {key uuid, vector position}, in that order, and you will also always get an integer status value at the end of your result list.  In between, you might get other values if you have requested them with RC_DATA_FLAGS.  So (key)llList2String(results,0) will always be the UUID.

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 3003 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...