Jump to content

How to apply an "impulse" to an object


Recommended Posts

Hi there, I´m a bit confused about some core concepts with Arcade Physics... I´ll try to explain it because actually it´s a little bit confusing even to understand what´s going on.

The thing is that I have a game where the main character is falling like if he jumps from the top of a building and when I init that sprite, I just apply a gravity to him

this.prota.body.gravity.y = 700

Then, on both sides of the game I have some mushrooms and some black-weird-plant-arms and when you hit them, I want the player to receive like an impulse, I mean, I want the player to "be launched like a rocket" and I make this with a callback of a collide() in the update() of the game

//in the update()
this.physics.arcade.collide(this.prota, this.grupoSetas, null, this.reboteSeta, this)

//and the callback
reboteSeta:function(prota, seta){
        //some code

        this.prota.body.acceleration.y = 0;
        this.prota.body.acceleration.x = 0;
        this.prota.body.velocity.y = -1000;
        this.prota.body.velocity.x = this.rnd.between(-1000, 1000);

        //some other code


The problem I have, is that the first time the player hits the mushroom, he rebounds only a little bit and then the rest of the times he rebounds properly and I´m really confused about this, I don´t know why this is hapenning...


Can anyone let me know what and why this is hapenning?


You can test it here

Link to comment
Share on other sites

1 hour ago, samid737 said:

A wild guess,maybe you have to use collideCallback instead of processCallback?



Awesome, that fixed the problem!

What´s the difference between those two calls? Well, I´m gonna check the docs, I guess I´ll find info there :)

Thanks for helping me with this!

Link to comment
Share on other sites


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...