[SOLVED] Apply impulse to balls on input (VR)

Hi everyone,

I am very new to PlayCanvas, but I have some experience with Unity. I am trying to put together a little VR demo for a group of very young students to get excited about technology. I forked a project from the VR demo. All I wish to accomplish is the following:

Add collision to the environment. - DONE
Add some balls with physics to the environment. - DONE
Apply impulse to the balls on input. - Struggling

If anyone could help me out, I, and the young women who will benefit from this project, would be greatly appreciative.

Thanks!
-Nizzl

How are you applying impulse to the balls related to input?
What input are you using? Vive? Rift Touch? Gamepad? etc
Are you struggling with the input, applying the impulse or the bit ‘inbetween’?
Can you share a link to the project?

Hey man,

. I found an already working VR demo and am trying to essentially just add a few objects that react to input (balls that bounce around). The goal of the workshop is to show the girls the room/let them play around, then walk them through coding some functions into a new object (the ball)
Here is the original project I worked from: https://playcanvas.com/project/446331/overview/webvr-lab
I forked that project and made a few little changes to fit the needs of what we are trying to accomplish with our workshop.
This is the project I’m working off of currently: https://playcanvas.com/project/490229/overview/vr-room-demo

I basically just want a click or any input to add a force to the balls.

To answer your question, we will be using a combination of iOS and Android devices for the little workshop for the kids we’re doing

I found the issue. Forked project is here with just the single ball: https://playcanvas.com/editor/scene/534073

At some point, you changed:

var Ball = pc.createScript('ball');

to

var Ball = pc.createScript('Ball');

And not reparsed the script file so the script registry of the engine now had a script of type ‘Ball’ but the entity was still trying to add ‘ball’ instead.

Change it back to:

var Ball = pc.createScript('ball');

Reparse the script and remove all the unused copied code as they are referencing functions that don’t exist in the script.

var Ball = pc.createScript('ball');

// initialize code called once per entity
Ball.prototype.initialize = function() {
    this.entity.on('object:interact', this._onInteract, this);
};

Ball.prototype._onInteract = function (controller) {
    this.entity.rigidbody.applyImpulse(10, 10, 0);
};

That will get you going to implement the rest of the functionality you want.

Thank you so much for your time!