Jump to content

RayCast Target? hitting self fix?


Altier Verwood
 Share

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

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

Recommended Posts

Hey there LSL people, I am working on a vehicle with a raycast weapon on it, and I have it kind of working using this.

 

But I've run into a problem, when aiming straight a head the ray is blocked by something? but since i can't see the ray it's hard to tell whats blocking it. is there a way I can move the start of the ray projection forward by like 5 meters? I tried adding  llGetCameraPos()+<5,0,0>; but that doesn't seem to work either the ray just doesn't hit anything at that point.

                vector start = llGetCameraPos();
                list results = llCastRay(start, start+<range,0.0,0.0>*llGetCameraRot(),[RC_REJECT_TYPES,RC_REJECT_LAND,RC_DETECT_PHANTOM, FALSE,RC_DATA_FLAGS,RC_REJECT_PHYSICAL, TRUE,RC_GET_ROOT_KEY,RC_MAX_HITS,15]);
            llSleep(0.03);
            key target = llList2Key(results,0);
                llTriggerSound(fire_sound, 1.0);
                llResetOtherScript("Bolt1");
                llRegionSayTo(target,gTargetChan, damage_type);
                llResetOtherScript("m_f");
                llSleep(delay);

Link to comment
Share on other sites

1 hour ago, Altier Verwood said:

I tried adding  llGetCameraPos()+<5,0,0>;

You forgot to multiply that start position by the camera rotation.

 

1 hour ago, Altier Verwood said:

but since i can't see the ray it's hard to tell whats blocking it.

It's good practice to add instrumentation/diagnostic code to help visualize things when you're trying to track down a problem. In this case, it would be helpful to rez an object at the ray's start and termination coordinates (and also the point of any ray hits).

As an example, the code below will check if it hit anything (the last value of the results list is always the number of hits). If we did hit something, the results list will always contain at minimum the uuid of the object hit, and the global position of the hit. You can use that to rez markers. (don't forget to add a prim called "marker" to the object's inventory. Also consider making it temporary to auto clean up)

llRezObject("marker", start, ZERO_VECTOR,ZERO_ROTATION, 0); //rez marker at ray origin point
if (llList2Integer(results, -1) > 0)   //check if we hit something
{
    llOwnerSay("Hit " + llKey2Name(llList2Key(results,0))); //say name of what we hit
    llRezObject("marker", llList2Vector(results,1), ZERO_VECTOR,ZERO_ROTATION, 0); //rez marker at impact position
}
else    //we didn't hit anything
{
    llOwnerSay("No hits");
    llRezObject("marker", start+<range,0.0,0.0>*llGetCameraRot(), ZERO_VECTOR,ZERO_ROTATION, 0); //rez marker at ray termination point
}
            

 

Edit: I had made a comment about RC_MAX_HITS 15 being potentially high for what I assumed is a hit-scan weapon. But I don't know your use case nor how you're processing the results list. Suffice to say, having as few max_hits as possible is preferable if possible, as it saves yourself some work. That of course depends entirely on what you're doing with the ray's hits, so take from that what you will.

Edited by Fenix Eldritch
  • Like 2
Link to comment
Share on other sites

but i have that already in the cast ray?  do i need to do it again?

              list results = llCastRay(start, start+<range,0.0,0.0>*llGetCameraRot(),[RC_REJECT_TYPES,RC_REJECT_LAND,RC_DETECT_PHANTOM, FALSE,RC_DATA_FLAGS,RC_REJECT_PHYSICAL, TRUE,RC_GET_ROOT_KEY,RC_MAX_HITS,15]);

Link to comment
Share on other sites

37 minutes ago, Altier Verwood said:

but i have that already in the cast ray?  do i need to do it again?

Yes, because both the start and end coordinates required by llCastRay are independent of each other.

Whenever you want to move a position in any direction relative to the current rotation, you need to multiply the  position (plus the offset) by that current rotation. This is necessary for the end position because it's some meters away. And once you try to move the start position forward of the current camera position, then that too needs to be multiplied by the current camera rotation in order to keep it along the same direction.

Edited by Fenix Eldritch
  • Like 1
Link to comment
Share on other sites

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