Ray Sphere Intersection Function (Demonstration) by BestLizard#1847
This code is over 6 months old. The code may have expired and might no longer function.
IF YOU USE THE FUNCTION, PLEASE KEEP CREDIT TO ME IN THE RULE NAME!!!
(This code has been written for the PTR version. It will be updated once functions, loops, etc. come to the live version of Overwatch)
Ray-Sphere Intersection
All input and output go through a single global variable. By default, global variable 3 is used, but this can be easily changed for your game mode by pasting the subroutine itself into a text editor. This global variable is an array, with indices 0-3 being the input, and 4-9 being the output.
I/O Breakdown
Inputs
0: Ray origin (ie eye position)
1: Ray direction (ie facing direction of)
2: Sphere Centre
3: Sphere Radius
Outputs
4: If ray intersects sphere (true if hit)
5: If sphere is behind player (true if sphere is entirely behind player. False if player is in sphere, or if sphere is ahead of player. Calculated as a courtesy)
6: Intersection Distance 1 (distance along the ray from origin to first intersection with sphere)
7: Intersection Distance 2 (distance along the ray to second intersection with sphere)
8: Intersection Position 1 (the first exact location an intersection occurs. Calculated as a courtesy)
9: Intersection Position 2 (the second exact location an intersection occurs. Calculated as a courtesy)
NOTE: Outputs 5-9 have GARBAGE if no intersection occurs with the ray. Always check index 4 after this function completes!
Demonstration
The game mode settings and additional rules are included in this import code to demonstrate usage of the function. The snippet on this site contains only the ray-intersection function: paste that into your game mode if you want to use it. Feel free to use it in any game mode, just please keep credit to me in the rule name.
Archival Notice
This post was originally hosted on workshop.elohell.gg, a site which is no longer online. If this was originally your post, you may click the button below to transfer this post to your Workshop.codes account or delete this post entirely.
Archive ActionsSnippet
Loading...