Build a Raycast Target in Banter
BanterScene.Raycast() casts from an origin in a direction for a specified distance and layer mask. A hit GameObject receives the intersection event with the hit point and surface normal.
Create a target with a collider, register its intersection listener, then cast the ray from the scene.
- Create visible target geometry with a matching collider.
- Listen for
intersectionon the target GameObject. - Call
scene.Raycast()with origin, direction, distance, and layer mask.
Create the Target
const target = new BS.GameObject({
name: "RaycastTarget",
localPosition: new BS.Vector3(0, 0, 0)
});
target.AddComponent(
new BS.BanterBox({
width: 1,
height: 0.25,
depth: 1
})
);
target.AddComponent(
new BS.BoxCollider({
isTrigger: false,
center: new BS.Vector3(0, 0, 0),
size: new BS.Vector3(1, 0.25, 1)
})
);
Add a Visible Material
target.AddComponent(
new BS.BanterMaterial({
shaderName: "Unlit/Diffuse",
texture: "",
color: new BS.Vector4(1, 0.3, 0.2, 1),
side: BS.MaterialSide.Front,
generateMipMaps: false
})
);
Listen for the Intersection
target.On("intersection", (event) => {
console.log(
"Ray hit:",
event.detail.point
);
console.log(
"Surface normal:",
event.detail.normal
);
});
The official event reference supplies both values as vectors.
Cast the Ray
scene.Raycast(
new BS.Vector3(0, 1, 0),
new BS.Vector3(0, -1, 0),
100,
0
);
The documented arguments are:
- ray origin
- ray direction
- maximum distance
- layer mask
The official example uses 0 to include all layers.
Cast in Another Direction
scene.Raycast(
new BS.Vector3(0, 1.5, 0),
new BS.Vector3(0, 0, 1),
20,
0
);
Use a direction vector that points from the chosen origin toward the intended target area.
Common Questions
Why does my Banter target never receive intersection?
Check the ray origin, direction, maximum distance, target collider, and layer-mask value. The hit GameObject receives the documented intersection event.
Where is the Banter raycast hit position?
Read event.detail.point inside the target's intersection handler. The surface normal is event.detail.normal.
Official References
Related Navigation
- Banter Raycasts and Object Events
- Banter Physics and Grabbable Objects
- Banter SDK Enums and Constants
- Banter VR Documentation