Jump to content

Collisions and velocity


Skeptron
 Share

Recommended Posts

Hi everyone!

 

First I would like to say that I really appreciate working with Phaser, definitely a great framework! The documentation is awesome and the support quite amazing! =)

 

I have found that when a sprite body collides with something, its velocity is immediatly reduced to zero. I can totaly figure out why and think that it's pretty handy, but I have encountered a frustrating situation that would gladly  bypass this behavior. 

 

When my character is stuck against a wall, and I want him to jump over it, then I press the LEFT and UP arrow simultaneously. But as my character is against a wall, its x velocity is put to zero immediatly, thus he jumps and falls where he was, without moving horizontaly. 

 

For my case I coded a workaround, but I just wanted to know if there is a property or a method I have missed that could prevent this behavior. My workaround implies a line of code in the update() method, which I would like to keep, for performance purposes, as short as can be.

 

Thank you for your help!

Link to comment
Share on other sites

Try putting the player's command functions after the collisions checks not before, otherwise, reusults from collisions checks might override orders you send to players's body.velocity.x

 

I guess that should do the trick.

Link to comment
Share on other sites

Sorry I forgot to mention that I do not update the coordinates in the update() function, I rather bind my keys to the character's move functions in the create() function with KeyBoard.keys and the onDown.add() and onUp.add() methods. Even though the result might probably be the same, it implies that I have no code in the update() function re-adjusting the coordinates, thus I can not tweak the order of the code doing so.

Link to comment
Share on other sites

Well, the problem might be just that.

 

You're probably not doing it like it is supposed to be done.

 

 

Look here:

 

http://examples.phaser.io/_site/view_full.html?d=games&f=starstruck.js&t=starstruck

 

I'm not saying your method is wrong or stupid, I'm just suggesting that you should stick to the way things are supposed to be handled according to phaser's creator method/logic.

 

Otherwise, you'll probably get unexpected results.

And you don't want unexpected results.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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