Body not moving when calling applyForce

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
Sawbones
Prole
Posts: 2
Joined: Fri Apr 15, 2016 10:52 pm

Body not moving when calling applyForce

Post by Sawbones »

Code: Select all

local Class = require 'lib.hump.class'

local Player = Class{
    init = function(self, x, y)
        self.body = love.physics.newBody(world, x, y, "dynamic")
        -- self.shape = love.physics.newRectangleShape(50, 50)
        -- self.fixture = love.physics.newFixture(self.body, self.shape, 1)
        self.image = love.graphics.newImage("assets/helo.png")
    end,
    update = function(self, dt)
        if love.keyboard.isDown('d') then
            self.body:setAngle(.4)
            self.body:applyForce(200, 0)
        elseif love.keyboard.isDown('a') then
            self.body:setAngle(-.4)
            self.body:applyForce(-200, 0)
        else
            self.body:setAngle(0)
        end
    end,
    draw = function(self)
        local x, y = self.body:getPosition()
        local width, height = self.image:getDimensions()
        love.graphics.draw(self.image, x, y, self.body:getAngle(), .5, .5, width/2, height/2)
    end
}

return Player;

When I press 'a' or 'd' the angle changes but the applyForce does not move my sprite.
User avatar
pgimeno
Party member
Posts: 3713
Joined: Sun Oct 18, 2015 2:58 pm

Re: Body not moving when calling applyForce

Post by pgimeno »

Works for me using your snippet. I can't say what you're doing wrong without a complete example.
User avatar
Tanner
Party member
Posts: 166
Joined: Tue Apr 10, 2012 1:51 am

Re: Body not moving when calling applyForce

Post by Tanner »

Shot in the dark but maybe you aren't updating your world object. https://love2d.org/wiki/World:update
Post Reply

Who is online

Users browsing this forum: Amazon [Bot], Bing [Bot], Google [Bot], Semrush [Bot] and 6 guests