ItHadToComeToThis Posted April 21, 2020 Share Posted April 21, 2020 (edited) 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 April 21, 2020 by ItHadToComeToThis Link to comment Share on other sites More sharing options...
Lucia Nightfire Posted April 21, 2020 Share Posted April 21, 2020 Due to the horrible rhomboid-like shape of the user physics shape, I think you're better off just checking distances and/or offsets. Maybe declare and reference a generic bounding box or agent size. Link to comment Share on other sites More sharing options...
Wulfie Reanimator Posted April 21, 2020 Share Posted April 21, 2020 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? Link to comment Share on other sites More sharing options...
ItHadToComeToThis Posted April 21, 2020 Author Share Posted April 21, 2020 (edited) 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 April 21, 2020 by ItHadToComeToThis Link to comment Share on other sites More sharing options...
Wulfie Reanimator Posted April 21, 2020 Share Posted April 21, 2020 (edited) 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.) 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 April 21, 2020 by Wulfie Reanimator 1 Link to comment Share on other sites More sharing options...
ItHadToComeToThis Posted April 21, 2020 Author Share Posted April 21, 2020 @Wulfie Reanimator Thank you. Muchly appreciated. I really need to get better at rotations! 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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