github link:https://github.com/adnzzzzZ/windfield#create-a-world
The documentation says.
Capture collision events
Collision events can be captured inside the update function by calling the enter, exit or stay functions of a collider. In the example below, whenever the box collider enters contact with another collider of the Solid collision class it will get pushed to the right:
function love.update(dt)
...
if box:enter('Solid') then
box:applyLinearImpulse(1000, 0)
box:applyAngularImpulse(5000)
end
end
So basically what I want to do is switch animations to a pushing animation when the player is in contact with ObjectA pushable objects by switching the players state to "pushing" if the player collider is staying on contact with the box or pot of ObjectA class. I cant really seem to get the collision to check and when it does its only like for a mirco split second when I use the collider:enter("ObjectA") and it then skips to the walking state imedietly. Its a logical error so they syntax seems fine but the way i'm doing it must be wrong or something.
Firstly I set up a physics world called myWorld in main.lua line 4.
Code: Select all
wf = require("libs/windfield-master/windfield")
myWorld = wf.newWorld()
Code: Select all
myWorld:addCollisionClass("ObjectA")
myWorld:addCollisionClass("ObjectB")
myWorld:addCollisionClass("Player", {ignores = {"ObjectB"}})
Code: Select all
layer.player = {}
layer.player.collider = myWorld:newCircleCollider(
player.x + player.width/2,
player.y + player.height/2,
player.width/3
)
layer.player.vx = 0
layer.player.vy = 0
layer.player.ox = player.width/2
layer.player.oy = player.height/1.5
layer.player.direction = "south"
layer.player.state = "standing"
layer.player.speed = 16*4
layer.player.collider:setFixedRotation(true)
layer.player.collider:setCollisionClass("Player") --player object ignores static objects
layer.player.collider:setObject(layer.player)
Code: Select all
--control player state
if self.player.collider:stay("ObjectA") then
self.player.state = "pushing"
else
if self.player.vx == 0 and self.player.vy == 0 then
self.player.state = "standing"
else
self.player.state = "walking"
end
end