Author Topic: Can someone explain to me exactly how containerRaycast works?  (Read 1119 times)

I'd like to know because I should have learned a long time ago.

%raycast = containerRaycast(%start,%end,%type,%ignore)

%start is the starting position in the world.
%end is the ending position in the world.
%type is the typemask, type of object, that the raycast will be colliding with.
%ignore is an optional object that is a member of the typemask to ignore collisions with.

It draws an invisible line between %start and %end. The first object it collides with on that line is the result.

If there is a result, it returns this:
%collision SPC posx SPC posy SPC posz SPC normalx SPC normaly SPC normalz

If there is no results, I think it returns 0 or -1.

To get the object it collided with use firstWord(%raycast). To quickly get the normal and positions use posFromRay and normalFromRay.

You can use it along with trig and maths to find an object the player is looking at, fire an invisible projectile between bricks, make instant hitting weapons, lots of things that it can do.

Neat.

So to fire a containerRaycast from a player to whatever it's looking at, what kind of math would be involved? Vector stuff, I'd guess?