Banter Raycasts, Clicks, Collisions, and Trigger Events
Banter GameObjects can emit click, grab, drop, collision, trigger, raycast-intersection, and browser-message events. BanterScene.Raycast() casts a ray through the scene, and an object hit by that ray receives an intersection event.
Give the target the required collider or interaction component, register its event listener, then cast or trigger the interaction.
- Create the target GameObject and add the collider or component required by the event.
- Register the listener before the interaction can occur.
- Read the hit point, normal, hand, object, tag, or user from the documented event detail.
Cast a Ray
scene.Raycast(
new BS.Vector3(0, 1, 0),
new BS.Vector3(0, -1, 0),
100,
0
);
The official arguments are:
- origin
- direction
- distance
- layer mask
The reference uses 0 for all layers.
Receive the Intersection
target.On("intersection", (event) => {
console.log(event.detail.point);
console.log(event.detail.normal);
});
The event provides the hit point and surface normal.
Register intersection on the GameObject expected to receive the ray, not only on the script that casts it.
Click Events
target.On("click", (event) => {
console.log(event.detail.point);
console.log(event.detail.normal);
});
Click events expose the hit point and surface normal.
Grab and Drop Events
target.On("grab", (event) => {
console.log(event.detail.point);
console.log(event.detail.side);
});
target.On("drop", (event) => {
console.log(event.detail.side);
});
The hand value uses BS.HandSide.
The object also needs the appropriate Banter grab component for normal VR grabbing.
Collision Events
Collision events require BanterColliderEvents:
target.AddComponent(
new BS.BanterColliderEvents()
);
target.On("collision-enter", (event) => {
console.log(event.detail.name);
console.log(event.detail.tag);
console.log(event.detail.point);
console.log(event.detail.normal);
});
If the collision involves a player, the documented detail can include event.detail.user.
Listen for collision-exit when the system must react after contact ends.
Trigger Events
Set the collider's isTrigger value to true, then listen for:
target.On("trigger-enter", (event) => {
console.log(event.detail.name);
});
target.On("trigger-exit", (event) => {
console.log(event.detail.name);
});
A trigger detects entry and exit without using the normal physical collision response.
Browser Messages on a GameObject
A GameObject with a browser component can emit:
browserObject.On("browser-message", (event) => {
console.log(event.detail);
});
Use this with the documented Banter browser message bridge.
Common Questions
Why does my Banter raycast not call the listener?
Check the ray origin, direction, distance, layer mask, target collider, and that the intersection listener is registered on the target GameObject.
Why do collision events never fire?
Add BanterColliderEvents and confirm the GameObject has a collider configured for the intended collision.
Why does my trigger push the object physically?
Set the collider's isTrigger value to true when it should detect entry and exit without a normal collision response.
Official References
Related Navigation
- Banter Controller Input and Haptics
- Banter Physics and Grabbable Objects
- Banter Interactive Browsers and Messages
- Banter VR Documentation