📰Getting Started | ⭐**Updates |** 📝 Guides | 🔢 API | ❓FAQ
Web Editor Basics
HoloLens
Mobile
Meta Quest
Chapter Series Documentation
Assets
Scripting
Enklu Embedded
API Reference
Release Notes
FAQ
Contact
The Physics API provides access to simple raycasting. In time, they'll be more functionality available.
const physics = require('physics');
A raycast can be used to see if a ray intersects with a specific Element.
var element =this.findOne('..(@name=Cube)');
var hit = physics.raycast(v.zero, v.forward, element);
if (hit) {
log.info('Hit! ' + hit);
}else {
log.info('Miss :(');
}
Change the gravity in your experience with the functions below. You can set the direction gravity is applied in the x, y and z world axes.
This will affect elements fired by the Projectiles API (coming soon), or any elements that have a physics-enabled Asset attached (see Rigidbody).
A positive value will head in the positive direction of that axes, and negative will go negative. It’s slightly counterintuitive, but to simulate normal gravity, make sure the gravity in the y axis is negative. The parameters are not accepting the overall intensity of the gravity in that axis; rather, they define the direction and acceleration of the gravity in that axis.
// set gravity in the x, y and z axes
physics.setGravity(float xGravity, float yGravity, float zGravity)
// examples
physics.setGravity(0, 0, 0); // zero gravity
physics.setGravity(0, -9.8, 0); // Earth gravity
physics.setGravity(0, 9.8, 0); // reverse Earth gravity (fly into space!)
physics.setGravity(1, 0, 0); // woah, going off to the side!
// reset gravity to Earth gravity, which is equivalent to setGravity(0, -9.8, 0);
physics.resetGravity();
<aside>
💡 Gravity will be reset back to Earth gravity (same result from calling resetGravity()
) when you exit the experience.
</aside>
raycast(start, direction, element)
start <vec3>
Start point.direction <vec3>
Direction the ray is cast.element <Element>
The target element.vec3
representing where the ray touched the element or null if the element is not hit.Casts ray and tests for collision with an Element.
setGravity(xGravity, yGravity, zGravity)
xGravity <number>
gravity in the x axis.yGravity <number>
gravity in the y axis.zGravity <number>
gravity in the z axis.resetGravity()
setGravity(0, -9.8, 0)
Next: Proximity
Sidebar Table of Contents
Copyright © 2021 Enklu, Inc.