Jump to content

Hopping because of vertical moving platform


Mercutio
 Share

Recommended Posts

Hi,

I am trying to build a platformer and when my player is standing on a vertically moving platform it hops at the peak right when it changes direction.

In the real world it makes sense but unwanted in game...

Does anyone have any suggestions how to fix the issue?

 

Some context:

I am using arcade physics.

I am moving my platform using velocity as I understand it I need to do it that way so the player sticks for horizontal movement.

 

Thanks

 

Do you guys need to see my code for this? if so which part?

Link to comment
Share on other sites

It's not straightforward using the physics mechanics. You could set the sprite body's bounce.y = -1 or gravity.y = a large positive number when it contacts the platform, then change it back to release the sprite.

The other way is to set body.moves = false while the sprite is on the platform and position it manually.

Link to comment
Share on other sites

For those who have a similar problem, here's what I ended up doing seems to work well enough. Don't know how fail safe or efficient it is though.


//in the scene
this.physics.add.collider(player, platforms, ride);

//collision callback with platforms
function ride(object1, object2){
        //check for if you actually step on the platform not just collide
	if(object1.body.touching.down)
	{
		object1.ride(object2);
	}
	
}


//in player object
ride(rideObject){
	this.riding = true;
	this.rideObject = rideObject;
}



//in update after movement
if(this.riding){
   this.y = this.rideObject.y -  (this.height/2 + this.rideObject.height/2);
   if(this.key_W.isDown || this.x < this.rideObject.x - this.rideObject.width/2 || this.x >    this.rideObject.x + this.rideObject.width/2 ){
      //jump // fall off
      this.riding = false;
   }
}

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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