Is it at all possible to create a physics body that has a flat bottom with a semi-circle top to it? I’m relatively new to physics programming. Thanks in advance.
@TheHam Yes. Use POLYGON and create the semi-circle with a bunch of vec2 values.
@TheHam Here’s an example of a semi-circle physics body.
displayMode(FULLSCREEN)
function setup()
physics.continuous=true
e1=physics.body(EDGE,vec2(0,0),vec2(WIDTH,0))
e2=physics.body(EDGE,vec2(0,0),vec2(0,HEIGHT))
e3=physics.body(EDGE,vec2(WIDTH,0),vec2(WIDTH,HEIGHT))
e4=physics.body(EDGE,vec2(0,HEIGHT),vec2(WIDTH,HEIGHT))
sim={}
for z=0,180,1 do
x=math.cos(math.rad(z))*100
y=math.sin(math.rad(z))*100
table.insert(sim,vec2(x,y))
end
s=physics.body(POLYGON,unpack(sim))
s.x=300
s.y=300
s.restitution=1
s.friction=0
b=physics.body(CIRCLE,30)
b.x=250
b.y=HEIGHT-50
b.restitution=1
b.friction=0
stroke(255)
strokeWidth(2)
fill(255)
end
function draw()
background(40, 40, 50)
pushMatrix()
translate(s.x,s.y)
rotate(s.angle)
p=s.points
j=#p
for z=1,#p do
line(p[j].x,p[j].y,p[z].x,p[z].y)
j=z
end
popMatrix()
ellipse(b.x,b.y,60)
end
I would increase the increment in the for
loop to 5 or so: for z = 0,180,5 do
. Gives Box2D and your draw loop a fifth the number of points to worry about.
Thanks guys, didn’t think of running a for loop, much appreciated.