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
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?