Jump to content

Weird issue on the exact same code which works in one instance but not in another


kriket
 Share

Recommended Posts

So I am trying to respawn spikes that fall on the player using this function.

 

    killSpike: function(a, b, c, d) {
        b.y = 100;
        b.x = this.game.rnd.integerInRange(this.game.width*1.2, this.game.width*1.6);
    },
 
We are just placing them again (after they collide with the floor) and expect them to fall straight down, under gravity. The problem is that I have noticed that the spikes are spawned with some sort of a slight bounce or bump, which doesnt cause them to fall straight down but causes them to fall diagonally. This is not what we want as spikes have to fall straight on player. Funny thing is, I had used the exact code before to spawn another obstacles in another game and that worked as expected. Respawned at a point and fell straight down. No slight bouncines during spawning/placing. 
 
I check all the code. No restitution is defined. Only gravity, which is same as in the earlier game I mentioned. All thats changed from that game is the sprite. But thats just how the sprite looks. Rest of code and physics is exactly the same. 
 
Any ideas how I can stop this slight bounciness during spawning/placement so they dont fall diagonally?
 
 
NOTE: its not exactly bounciness. Its just that when a sprite is spawned/placed, it sometimes is already moving horizontally before getting affected by gravity. This makes it fall diagonally like rain. 
Link to comment
Share on other sites

Hello,

 

I would suggest adding jsfiddle example of the behaviour - extract just necessary parts of your game not the entire game, no one wants to go through all the code.

 

Otherwise how about trying reset, does the same bevaiour occurs when you use reset to set new positions and properties (somethingl ike b.reset(newX, newY);)?

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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