Re-impulse doesn't work(?)

Hi all
I use the applyImplulse function to shoot a ball out of a staff. That works well, but only once, the very first time. The second time the ball straight falls down (w/o impulse in it).

    onMouseDown: function (event) {
        // If the left mouse button is pressed, change the cube color to red
        if (event.button === pc.input.MOUSEBUTTON_LEFT) {
            var ballEntity = context.root.findByName('Ball');

            // Active ball shoot
            if (ballEntity.enabled == false) {
                ballEntity.rigidbody.applyImpulse(1.5, 10, -10, 0, 0, 0);
                ballEntity.enabled = true;


When the ball falls far down I reset its position in front of the staff for re-shooting and set the ball to enable = false.

The only thought about that fact is that the second impulse might somehow “collide” with the first impulse, but there is no “destroyImpulse” function, so it might disappear itself.

Sorry, correction: The balls after the first shoot are not falling straight down. They fall like a falling airplane (but not going first up and then down). I guess the first impulse is still active on the ball.
So the question is: How can I destroy the first impulse to add a new one?

Anyone has an idea?

You seem to have chosen quite an arbitrary vector for the impulse. You probably want the impulse to be the direction the staff is pointing. Because the staff is a cylinder primitive which, by default, is aligned to the entity’s local Y axis, you should probably use a vector more like this:

var staffDirection = this.entity.up.clone();
ballEntity.rigidbody.applyImpulse(staffDirection, pc.Vec3.ZERO);

Also, I notice you have a translation on the root node in your scene hierarchy. You probably don’t want that. :smile: Set it to 0, 0, 0.

You are setting the position of the ball when it falls below a certain height. If you ever explicitly set the position or rotation of an entity that has a rigidbody component that is of type ‘dynamic’, you must immediately call entity.rigidbody.syncEntityToBody() straight afterwards. This tells the physics engine to move the rigid body to wherever the entity is (in the event you’ve moved it).

Lastly, if you ever reset the position of a dynamic rigidbody entity, it is likely that you will want to also reset its linear and angular velocity. You do this as follows:

entity.rigidbody.linearVelocity = pc.Vec3.ZERO;
entity.rigidbody.angularVelocity = pc.Vec3.ZERO;

Hope that helps.

Hi will
Thanks a ton for your great help. It made me speechless like your great engine! To honor and support I created playcanvas Pro account and will continue with it for a while.
I was aware of the problems you mention just didn’t know how to solve it yet. I still have to figure out certain mechanism and want to solve all of them step by step. What you all wrote is exactly I had to make my thoughts. I just didn’t know how to solve it. :wink: 3D is just different and need 3D thoughts…

I’m still not sure if my technical question was at right place here. I guess many people have technical questions, so therefore a forum category “Technichal questions” or so would make sense(?)

Things you mention like “…you must immediately call entity.rigidbody.syncEntityToBody() straight afterwards. …” would be helpfull reading in the documentation where its required after other functions/mechanisms. Might save your time while noobs like me are asking always the same questions. :slight_smile:

Yes, your information is very helpfull! As soon as I find further time I will continue with it in my project!

I’m curious what new features will come!

Greetings and huge thanks!

Great news that you have become a Pro user! :smile:

I guess we could add a Technical Questions category, but that’s kind of what the Answers site is for. Have you checked it out yet? You can find it here. This forum is more for general chat. But to be honest, I don’t mind where you post questions.

We will keep working on the documentation to make these kinds of things easier to understand. Feedback is always welcome and helps us improve what we have.

We have some exciting new features just around the corner. I won’t spoil the surprise, but we should be able to make an announcement in about 3 weeks time.