Page 1 of 1

How to make 2 way platform work properly

Posted: Tue Aug 29, 2023 4:48 pm
by Sammm
Hello! I'm attempting to make a two way platform with the love.physics module, and currently the behavior is quite strange. The player will occasionally glitch through the platform, and when the player lands on the platform, the player phases through for a split second then returns to its normal position. I believe this is because I'm switching the platform shape to a trigger once the player hits the platform, not before it, causing this unresponsive behavior. Any ideas on how to improve this design would be great.

Here's the demo and full code:
platform.love
(1.7 KiB) Downloaded 105 times

Re: How to make 2 way platform work properly

Posted: Tue Aug 29, 2023 4:53 pm
by BrotSagtMist
Just forcefully set it to the position or remove all the players vertical velocity during the trigger.

Re: How to make 2 way platform work properly

Posted: Tue Aug 29, 2023 7:41 pm
by Sammm
I tried doing that, like this:

Code: Select all

       self.velX, self.velY = self.body:getLinearVelocity()

	if self.onPlatform then
	 	self.body:setY(self.platform:getBody():getY() - self.height/2 - 9)
	 	self.body:setLinearVelocity(self.velX, 0)
        end
but now the player gets absolutely frozen on the platform and I can't figure out why.

Updated code & demo: