Untitled

📰Getting Started | **Updates |** 📝 Guides | 🔢 API | ❓FAQ

Guides Overview

The Physics API provides access to simple raycasting. In time, they'll be more functionality available.

const physics = require('physics');

Raycasting

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 :(');
}

Gravity

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>

Module Methods

raycast(start, direction, element)

Casts ray and tests for collision with an Element.

setGravity(xGravity, yGravity, zGravity)

resetGravity()

Next: Proximity

Sidebar Table of Contents


Untitled

Copyright © 2021 Enklu, Inc.