How to make 2 way platform work properly

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Sammm
Prole
Posts: 37
Joined: Fri Sep 09, 2022 4:39 pm

How to make 2 way platform work properly

Post 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
Lua is LÖVE, lua is life
User avatar
BrotSagtMist
Party member
Posts: 657
Joined: Fri Aug 06, 2021 10:30 pm

Re: How to make 2 way platform work properly

Post by BrotSagtMist »

Just forcefully set it to the position or remove all the players vertical velocity during the trigger.
obey
User avatar
Sammm
Prole
Posts: 37
Joined: Fri Sep 09, 2022 4:39 pm

Re: How to make 2 way platform work properly

Post 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:
Attachments
platform.love
(1.71 KiB) Downloaded 73 times
Lua is LÖVE, lua is life
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 2 guests