- If Codea Sratch pad is like the “Demo” app why is is 5 dollars? Why not make a free "Demo"ish
- How can i make…like for example…print(“HIT!”) when a ball hits the right side of the wall, i know how to if you are using x,y positions…But what about Physics ball?(aka a invisible ball with a color circle fallowing it around) So my ? is how do i make it react to things? i know IF tests but cant seem to get it to work
- Thats it for now, THANKS FOR ANY HELP its really Apprerciated!!!
@EvanDavis, I don’t know about q1, but for q2 you can use the collide(contact)
function, which is called every time physics objects collide (similar to touched(touch)
, which happens every time a touch occurs).
@EvanDavis Here’s a little demo showing collisions. The code will print which ball collides with an EDGE or which 2 balls collide with each other.
function setup()
physics.continuous=true
e1=physics.body(CHAIN,true,vec2(0,0),vec2(0,HEIGHT),
vec2(WIDTH,HEIGHT),vec2(WIDTH,0))
e1.info="edge"
tab={}
for z=1,5 do
p=physics.body(CIRCLE,10)
p.x=math.random(WIDTH)
p.y=math.random(HEIGHT)
p.restitution=1
p.linearVelocity=vec2(200,200)
p.info=tostring(z)
p.gravityScale=0
p.friction=0
table.insert(tab,p)
end
end
function draw()
background(40, 40, 50)
for a,b in pairs(tab) do
fill(255)
ellipse(b.x,b.y,20)
fill(255,0,0)
text(a,b.x,b.y)
end
end
function collide(c)
if c.state==BEGAN then
print(c.bodyA.info,c.bodyB.info)
end
end
Perfect!! thanks dave