Jump to content

Raycasting help


ItHadToComeToThis
 Share

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

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

Recommended Posts

So i have been playing around with raycasting as a way to detect when someone is hit after a punch animation has been performed. Casting one ray is simple enough but, if the person isn't directly in the rays path then obviously it doesn't detect them. What i want to do is cast three or four rays to detect a person in front of you so if the person moves off to the side you can still hit them.....but.....if its not the central ray then it classes it as a glancing blow rather than a full blow. I am a little unsure on the best way to set that up to split the three different rays. Any help or suggestion of a better way to do it. The ray is 2m in length from the avatar

Edited by ItHadToComeToThis
Link to comment
Share on other sites

45 minutes ago, Wulfie Reanimator said:

Is this a math question? Do you want to know how to "spread out" the rays in some shape? Or do you need help figuring out how to decide which ray to use?

Both I guess. I need to fire a rat straight ahead but also outward either side of it so I am taking into account, roughly, the whole targets width and then determine from that whether my hit was a direct strike or a glancing blow that deals less damage. Unless there is a better way besides a sensor of doing it?

Edited by ItHadToComeToThis
Link to comment
Share on other sites

4 hours ago, ItHadToComeToThis said:

Both I guess. I need to fire a rat straight ahead but also outward either side of it so I am taking into account, roughly, the whole targets width and then determine from that whether my hit was a direct strike or a glancing blow that deals less damage. Unless there is a better way besides a sensor of doing it?

Well, the vector part is relatively easy.
(Just for reference: http://wiki.secondlife.com/wiki/LlCastRay)

You'll want to cast a ray from your position, two meters forward.
vector ray1 = <2,0,0> * llGetRot();

And you would call llCastRay like...
list ray = llCastRay(llGetPos(), llGetPos() + ray1, []);

Creating other rays that deviate from the first one is really simple. You just apply another rotation to it. This would offset the ray by 10 degrees horizontally:
vector ray2 = ray1 * llEuler2Rot(<0,0,10> * DEG_TO_RAD);

Visually speaking, the rays would look something like this: (And you can use the editing tools to figure out what rotations you need/want.)
d673004449.png

Programmatically speaking, you could implement the code something like this:

default
{
    state_entry()
    {
        vector pos = llGetPos();
        rotation rot = llGetRot();

        vector ray1 = <2,0,0> * rot;
        vector ray2 = ray1 * llEuler2Rot(<0, 0, 0.174533>);
        vector ray3 = ray1 * llEuler2Rot(<0, 0, -0.174533>);

        llOwnerSay(llList2CSV([ray1, ray2, ray3]));

        list ray = llCastRay(pos, pos + ray1, []);
        // Check for direct hit...

        ray = llCastRay(pos, pos + ray2, []);
        // Check for glancing hit...

        ray = llCastRay(pos, pos + ray3, []);
        // Check for glancing hit...
    }
}

 

Edited by Wulfie Reanimator
  • Like 1
Link to comment
Share on other sites

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