[Windfield physics] Jumping and collision detection problem

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
ilovelove2019
Citizen
Posts: 78
Joined: Wed Sep 11, 2019 10:38 am

[Windfield physics] Jumping and collision detection problem

Post by ilovelove2019 »

Hello. It's me again. I'm making a platformer and I get this problem. Let's get straight to the point. Here is some of my code:
Main.lua:

Code: Select all

function love.load()
    Object = require"classic"
    require "player"
    anim8 = require "anim8"
    windfield = require("windfield-master/windfield")
    world = windfield.newWorld()
    world:setGravity(0, 100)
    
    ground = world:newRectangleCollider(0, 550, 800, 50)
    ground:setType('static')
    world:addCollisionClass('Ground')
    world:addCollisionClass('Player')
    ground:setCollisionClass('Ground')
    
    player = Player()
end

function love.update(dt)
    world:update(dt)
    player:update(dt)
end

function love.draw()
    player:draw()
    world:draw()
end


player.lua:

Code: Select all

Player = Object:extend()

function Player:new()
    self.width = 50
    self.height = 37
    self.x = 200
    self.y = 200
    self.sx = 1
    self.onGround = false
    
    ....
    
    --physics
    self.collider = world:newRectangleCollider(200, 200, 27, 30)
    self.collider:setCollisionClass('Player')
end

function Player:update(dt)
    
    if love.keyboard.isDown("left") then
        self.collider:setX(self.collider:getX()-1)
        self.sx = -1
        self.anim = self.animations.run
    end
    if love.keyboard.isDown("right") then
        self.collider:setX(self.collider:getX()+1)
        self.sx = 1
        self.anim = self.animations.run
    end
    if love.keyboard.isDown("up") and self.onGround==true then
        self.collider:applyLinearImpulse(0, -100)
        self.anim = self.animations.jump
        print("ok")
        
    end
    if love.keyboard.isDown("down") then
       
    end
    
    if self.collider:enter('Ground') then
        onGround = true
        print("yes")
    end
    function Player:draw()
    self.x = self.collider:getX()---37 / 2-6
    self.y = self.collider:getY()--- 50 / 2+ 6
    self.anim:draw(self.sprites, self.x, self.y, nil, self.sx, 1, self.width / 2, self.height / 2)
end

    
    
    ----

    
end
I press 'up' but it not jump, not have 'ok' print to the screen. Can you help me? If you have better method for the player movement, please teach me. Thank you so much! Hope you will help me soon
ilovelove2019
Citizen
Posts: 78
Joined: Wed Sep 11, 2019 10:38 am

Re: [Windfield physics] Jumping and collision detection problem

Post by ilovelove2019 »

Bonus: I think my collision is wrong. I don't know what is the right method for detect collision in windfield. Pro please help me. Thank a lot!
ilovelove2019
Citizen
Posts: 78
Joined: Wed Sep 11, 2019 10:38 am

Re: [Windfield physics] Jumping and collision detection problem

Post by ilovelove2019 »

Ok. I give up and change to bump. Thanks everyone.
User avatar
4vZEROv
Party member
Posts: 126
Joined: Wed Jan 02, 2019 8:44 pm

Re: [Windfield physics] Jumping and collision detection problem

Post by 4vZEROv »

I also made a box2d wrapper if you want to try : https://github.com/4v0v/physics.
Post Reply

Who is online

Users browsing this forum: No registered users and 162 guests