physic doesn't work

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
PGUp
Party member
Posts: 105
Joined: Fri Apr 21, 2017 9:17 am

physic doesn't work

Post by PGUp »

ive been searching for 20 mins and i still dont know the problem..
so i was experimenting with accessing script from another lua file and i got a weird result

this is just a ball with physics..
(snake.lua)

Code: Select all

function snake_load()
snake = {}
snake.body = love.physics.newBody(world, 375, 275, "dynamic")
snake.shape = love.physics.newCircleShape(0, 0, 20)
snake.fixture = love.physics.newFixture(snake.body, snake.shape, 1)
snake.fixture:setRestitution(1)
snake.body:setGravityScale(1)
table.insert(Nsnake, snake)
end
and the main.lua

Code: Select all

require 'snake'
function love.load()
love.physics.setMeter(64)
world = love.physics.newWorld(0, 9.8 * 64, true)
Nsnake = {}
end

function love.update()
if love.keyboard.isDown("space") then
snake_load()
end
end

function love.draw()
for i,v in pairs(Nsnake) do
love.graphics.setColor(255,255,0)
love.graphics.circle("fill", v.body:getX(), v.body:getY(), 20)
end
end
so when i run it, the circle didn't fall or move at all.. its just stay there. Even when i changed the gravity scale from snake.lua, am i missing something ?
-
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: physic doesn't work

Post by raidho36 »

You need to manually update the world.
Post Reply

Who is online

Users browsing this forum: No registered users and 87 guests