Jump to content

CastRay


ItHadToComeToThis
 Share

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

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

Recommended Posts

Slowly getting back into SL and trying to refresh my scripting skills but, I have forgotten a fair amount on the use of Cast Ray.

Casting a basic ray is simple enough but, how on earth do I do this sensor event, but as a CastRay

llSensor("","",AGENT_BY_LEGACY_NAME,3.0,PI/3);

And make the cast ray ignore any and all objects except for the avatar?

  • Like 2
Link to comment
Share on other sites

22 minutes ago, Rolig Loon said:

If you are using llCastRay, you specify all the filters except RC_REJECT_AGENTS

6d5c1855ed81f8c4b790eddc788e1613.png

See https://wiki.secondlife.com/wiki/LlCastRay

Super, thank you!
How do you "arc" the ray though, that's the bit im struggling with the most. Trying to imagine how to cast it so it only covers a Pi/3 radius in front of the avatar.

  • Like 1
Link to comment
Share on other sites

I'm not sure exactly what you mean.  If you only want to detect avatars within a PI/3 cone, you write the llSensor statement accordingly, as you did above:

llSensor(" ", " ", AGENT, 3.0, PI/3);

Then,  you have the llCastRay statement in your sensor event, where you use the llDetectedPos(0) of the avatar that your sensor identified as the target vector for the cast ray.

  • Like 2
Link to comment
Share on other sites

2 minutes ago, Rolig Loon said:

I'm not sure exactly what you mean.  If you only want to detect avatars within a PI/3 cone, you write the llSensor statement accordingly, as you did above:

llSensor(" ", " ", AGENT, 3.0, PI/3);

Then,  you have the llCastRay statement in your sensor event, where you use the llDetectedPos(0) of the avatar that your sensor identified as the target vector for the cast ray.

Basically something along those lines. I would usually use a sensor to detect if someone is in front, let's say if my avatar was kicking someone. What I wanted to do was use a ray cast instead so that the avatar could hide behind something. A sensor doesn't allow you to ignore any objects in front of the avatar.

  • Like 1
Link to comment
Share on other sites

17 minutes ago, ItHadToComeToThis said:

Basically something along those lines. I would usually use a sensor to detect if someone is in front, let's say if my avatar was kicking someone. What I wanted to do was use a ray cast instead so that the avatar could hide behind something. A sensor doesn't allow you to ignore any objects in front of the avatar.

In that case, I would sensor, then cast a ray at any avatars found to check for an object in-between.

ETA: which is basically what was said above. RIP my reading comprehension.

Edited by Quistess Alpha
  • Like 4
Link to comment
Share on other sites

5 hours ago, ItHadToComeToThis said:

Super, thank you!
How do you "arc" the ray though, that's the bit im struggling with the most. Trying to imagine how to cast it so it only covers a Pi/3 radius in front of the avatar.

 

5 hours ago, ItHadToComeToThis said:

Basically something along those lines. I would usually use a sensor to detect if someone is in front, let's say if my avatar was kicking someone. What I wanted to do was use a ray cast instead so that the avatar could hide behind something. A sensor doesn't allow you to ignore any objects in front of the avatar.

Just to be clear, you can't really "arc" the ray, unless you were to cast and process dozens of individual rays. (Which isn't a very good idea.) You're gonna need the ray in addition to the sensor as Rolig suggested.

Depending on the specific use-case, it might be better to ignore avatars during the raycast and just make sure there's no other objects in the way. This is generally a more consistent way to detect line of sight if the target tends to be moving. Depending on their velocity and script lag, the avatar might move out of the way before the ray is cast.

  • Like 3
Link to comment
Share on other sites

On 3/3/2023 at 9:26 AM, Wulfie Reanimator said:

 

Just to be clear, you can't really "arc" the ray, unless you were to cast and process dozens of individual rays. (Which isn't a very good idea.) You're gonna need the ray in addition to the sensor as Rolig suggested.

Depending on the specific use-case, it might be better to ignore avatars during the raycast and just make sure there's no other objects in the way. This is generally a more consistent way to detect line of sight if the target tends to be moving. Depending on their velocity and script lag, the avatar might move out of the way before the ray is cast.

Yep, it's just me getting back into scripting again after a couple years of not really doing it. I forgot a few things but getting back into it now. Such as, RayCast has a start and end position so there's no need to do anything too fancy to achieve this. Amazing after a while of not doing it the things you do remember vs the small things you forget.

  • Like 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 489 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...