Hello!
I’m trying to make a circle shatter into a bunch of peices when you tap the screen, but I’m having trouble figuring out what points I need to use when creating the slices. I’m worried I might have to use some of the math functions I don’t understand like math.acos
, math.cosh
, math.asin
, math.sinh
, math.atan
, math.tanh
, math.fmod
, and math.log
(I do understand however, that cosine is adjecent / hypotenuse, sine is oposite / hypotenuse and tangent is oposite / adjecent in a triangle). Don’t blame me, I’m not in high school yet. I’ve tried learning these math functions through the internet, but that kind of math was very confusing. I’m hoping someone can help me here on the forums. I would love someone to help me write the code, but giving me some easy-to-understand tutorials on these math functions would also be great!
Here’s what I have so far:
-- Use this function to perform your initial setup
function setup()
borders = physics.body(CHAIN,true,vec2(0,0),vec2(WIDTH,0),vec2(WIDTH,HEIGHT),vec2(0,HEIGHT))
bodies = {}
newBody(physics.body(CIRCLE, 100), WIDTH/2, HEIGHT/2, vec2(0,0))
--newBody(physics.body(POLYGON,vec2(-100,-100),vec2(0,100),vec2(100,-100)),200,HEIGHT-100)
physics.gravity(0,-700)
end
-- This function gets called once every frame
function draw()
-- This sets a dark background color
background(40, 40, 50)
-- Do your drawing here
for k,t in pairs(bodies) do
pushMatrix()
translate(t.b.x,t.b.y)
if t.b.shapeType == POLYGON then
rotate(t.b.angle)
t.m:draw()
elseif t.b.shapeType == CIRCLE then
pushStyle()
fill(0,0,255)
noStroke()
ellipse(0,0,t.b.radius*2)
popStyle()
end
popMatrix()
end
end
function touched(t)
if t.state == ENDED then
-- First we create new bodies in the shapes of the circle sliced (how??)
bodies[1].b:destroy()
table.remove(bodies,1) -- Then we remove the original circle
end
end
function newBody(b, x, y, vel, ang, rotSpeed)
local velocity
if vel then
velocity = vec2(vel.x,vel.y)
else
velocity = vec2(0,0)
end
b.position = vec2(x,y)
b.linearVelocity = velocity
b.angle = ang or 0
b.angularVelocity = rotSpeed or 0
b.restitution = 0.4
local m = mesh()
if b.shapeType == POLYGON then
m.vertices = triangulate(b.points)
end
m:setColors(0,0,255)
table.insert(bodies, {b=b,m=m})
end
Thank-you so much in advance!