I'm having an issue with my player detecting when it is above the ball (windfield)

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
MaxGamz
Party member
Posts: 107
Joined: Fri Oct 28, 2022 3:09 am

I'm having an issue with my player detecting when it is above the ball (windfield)

Post by MaxGamz »

So I have been working on this platformer and I was able to get the ground and sky animations working. I came across an issue however with the animations when the player interacts with the ball. I want the player to play the idle/ground animations when self.grounded is true. What I want is for when the player hits the ball from the bottom, the grounded variable is unchanged, but when the player stands on the ball, I want it to be grounded. I'm using the windfield library for my physics. https://github.com/a327ex/windfield#cre ... on-classes

The section I used for this portion of the code is based off of the section about one-way platforms

Code: Select all

function Player:onBall() -- checks if the player is on top of the ball or not
    self.collider:setPreSolve(function(collider_1, collider_2, contact)
        if collider_1.collision_class == "Player" and collider_2.collision_class == "Ballz" then
            local heroPos = collider_1:getY() + 48     
            local ballPos = collider_2:getY() - collider_2:getRadius()
            if heroPos >= ballPos then self.grounded = true print(true) else
                self.grounded = false
            end
        end
    end)
end
For some reason, the console prints true even when the player touches the ball from the side and bottom even though I accounted for the y positions of both. How can I solve this?
User avatar
darkfrei
Party member
Posts: 1216
Joined: Sat Feb 08, 2020 11:09 pm

Re: I'm having an issue with my player detecting when it is above the ball (windfield)

Post by darkfrei »

Can the player stand on the top left corner of the ball?

Must be the player position and ball position show the point of contact or just middle point of them?

Where is the x-coordinate checking?
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
MaxGamz
Party member
Posts: 107
Joined: Fri Oct 28, 2022 3:09 am

Re: I'm having an issue with my player detecting when it is above the ball (windfield)

Post by MaxGamz »

darkfrei wrote: Thu Nov 03, 2022 8:10 am Can the player stand on the top left corner of the ball?

Must be the player position and ball position show the point of contact or just middle point of them?

Where is the x-coordinate checking?

I just used the y coordinates, I didn't code in for it to also check the x coordinates.
MaxGamz
Party member
Posts: 107
Joined: Fri Oct 28, 2022 3:09 am

Re: I'm having an issue with my player detecting when it is above the ball (windfield)

Post by MaxGamz »

darkfrei wrote: Thu Nov 03, 2022 8:10 am Can the player stand on the top left corner of the ball?

Must be the player position and ball position show the point of contact or just middle point of them?

Where is the x-coordinate checking?
I checked and the player can stand on the left corner of the ball
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 3 guests