raycast hit

raycast hit

raycasthit

Details

Kode wheel segment Sensors
Style Sensor
Modifiers objects only / terrain only / from / to / direction / length / draw
Primarily WHEN/DO WHEN
Pre-made brains that use it Unknown

Sensors > raycast hit

Description

This is a sensor tile. The raycast sensor is a thin line that extends from an object’s center socket along its forward facing vector. If that line hits an object or terrain it will register the following information: the distance between the two points, the position of the impact point, and the direction the object is facing. You can specify whether it detects objects or terrain. The line is very thin and very precise and if you experiment with it you will see that getting an object to line up with another to get a “hit” can be tricky. You can change the length of the line, but not the width.

Experiment with the draw modifier in place so you can see the raycast line. This sensor is quite powerful, but tricky to use. Only use it when you need precise sensor detection.

 

 

Example Code

 

WHEN [raycast hit] [terrain only] [length][3] DO

…WHEN [duration][1] DO [turn][left][slowly]

 

 

 

Modifiers

objects only: The raycast sensor will only register a hit on prop objects and characters

terrain only: The raycast sensor will only register a hit with terrain

from: Paired with a socket position or IWP object, the raycast can be altered from the center socket to start somewhere else.

WHEN [raycast hit][from][left foot][position] DO

to: Paired with an IWP object you can draw a raycast line between 2 objects, and only detect the specified object rather than all objects.

direction: By default the raycast will draw from the center socket and along the forward facing vector. Use this modifier to change the direction of the raycast

WHEN [raycast hit][direction][up]

length: Paired with a number you can specify the length of the raycast in meters.

draw: This will draw the raycast line in test and play mode. It is a thin white line that changes to green when it hits something by default.

Outputs

Display and Create outputs:

did hit object: A boolean variable. True if it hit an object (not terrain)

did hit terrain: A boolean variable. True if hit terrain (not object)

hit distance: A number variable. Gives the distance of the object or terrain that has been hit by raycast. Can be used with create.

hit position: A vector variable. Gives the vector position (3 coordinate numbers) of the raycast hit. Can be used with create.

hit surface normal: A vector variable. Gives the vector position of the “direction of the surface”. Surface normal is the direction a certain point on a surface is pointing to. That tile has to be used under a child line of a raycast WHEN and will be useful to find the direction of a surface like a slope on a terrain, and make that hit surface normal the up direction of a wolf character for example (very useful since he will stop clipping into a hill and actually follow the slope instead of climbing it with rear paws floating in the air). Let’s say a surface is at 30 degrees angle from flat terrain, the surface normal of that point will be at 90 degrees pointing outward from that surface point. 1 Can be used with create.

terrain material index: Experiments with this tile did not reveal how you use it. Can be used with create. EXPLANATION NEEDED

is temporary terrain: A boolean variable. Identifies whether terrain detected by the raycast hit is temporary or not.

 

Other Uses

See Tutorials What is a Ray cast? by Project Spark

Raycasting by Mescad

Comments are closed.

Website Powered by WordPress.com.

Up ↑

%d bloggers like this: