Page 1 of 1

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

Posted: Thu Nov 03, 2022 1:07 am
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?

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

Posted: Thu Nov 03, 2022 8:10 am
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?

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

Posted: Thu Nov 03, 2022 10:50 am
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.

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

Posted: Thu Nov 03, 2022 12:34 pm
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