# Why my physic not work?

I made a program to try about Codea physic, but it won’t work. Can someone tell my why, and how to use it? Thank you.

here is the code:

``````-- Physic

-- Use this function to perform your initial setup
function setup()
rectMode(CENTER)
ellipseMode(CENTER)
parameter.integer("y",0,1000,0)
a,b = physics.body (POLYGON,vec2(-50,-50),vec2(-50,50),vec2(50,-50),vec2(50,50)),physics.body (POLYGON,vec2(-50,-50),vec2(-50,50),vec2(50,-50),vec2(50,50))
a.x,a.y,a.interpolate,a.awake = WIDTH/2,2000,true,true
b.x,b.y = WIDTH/2,HEIGHT/5
b.type = STATIC
stroke(0, 0, 0, 255)
strokeWidth(3)
end

-- This function gets called once every frame
function draw()
b.y = y
strokeWidth(3)
local O = {a,b}
print (1/DeltaTime)
background(255, 255, 255, 255)
fill(136, 207, 224, 255)
for i = 1 , 2 do
pushMatrix()
translate(O [i].x,O [i].y)
rotate(O [i].angle)
rect(0,0,100)
popMatrix()
end
end
``````

Can you please try to explain what exactly you are trying to do? Maybe then we can help you more

@EvanDavis I just what to learn about physic, but I have come problem with that.

Can you speak English well? Or would you like to try a translator?

I can’t understand you, sorry.

@EvanDavis I need help with Codea physics, can you help me? Thank you. Sorry about my English.

In my experience (not much, but I’ve done some physics), codea’s physics engine doesn’t like to update while you’re manually changing the x or y position of a physics body. What this looks like is what you see when you move your static body around and the dynamic one doesn’t move. I don’t exactly know how to fix this, but I’ve gotten around it in the past by applying a minuscule linear impulse to the body and immediately cancelling it out by applying a miniscule linear impulse the exact opposite direction. I do this at the same time that I change the x or y value of a body and it seems to work. Hope this helps!

-Update: If you set a.sleepingAllowed = false and b.sleepingAllowed = false then most of your problems should be fixed. I’m still not sure about that box sliding into the other though. Good Luck!

@Attila717 Thank you very much! I will try this! Thank you! As @EvanDavis says, my English is not good because I’m Chinese! Thank you for the help!

@Gai_Gai Here’s an example similar to what your code was trying to do. Look it over and if you have questions, just ask.

``````displayMode(FULLSCREEN)

function setup()
rectMode(CENTER)

physics.continuous=true

physics.body(EDGE,vec2(0,0),vec2(WIDTH,0))  -- floor

a=physics.body (POLYGON,vec2(-50,-50),vec2(50,-50),vec2(50,50),vec2(-50,50))
a.x=WIDTH/4+51
a.y=HEIGHT

b=physics.body (POLYGON,vec2(-50,-50),vec2(50,-50),vec2(50,50),vec2(-50,50))
b.x=WIDTH/4
b.y=300
b.type=STATIC

fill(135, 217, 224, 255)
stroke(0)
strokeWidth(3)
end

function draw()
background(161, 223, 191, 255)

pushMatrix()
translate(a.x,a.y)
rotate(a.angle)
rect(0,0,100,100)
popMatrix()

rect(b.x,b.y,100,100)
end
``````

@dave1707 Thank you very much.