Hi!
I have question can i penetrate dynamic object?
I have hero, hero walking, hero passes dynamic object, object stay on his poistion, on my console i have print
(herro passes dynamic object)
Thanks in Advice
Hi!
I have question can i penetrate dynamic object?
I have hero, hero walking, hero passes dynamic object, object stay on his poistion, on my console i have print
(herro passes dynamic object)
Thanks in Advice
From the way it sounds, you want an object to be dynamic but stay in place?
If not, please explain some more.
Some code:
local physics = require("physics") physics.start() physics.setGravity( 0, 9.8 ) local hero = display.newRect(200,200 ,40, 50); hero.myName = "rect" hero:setFillColor( 1, 0, 0 ) physics.addBody(hero, "dynamic"); local obj = display.newRect(200,300 ,40, 50); obj.myName = "obj" obj:setFillColor( 0, 1, 0 ) physics.addBody(obj, "dynamic"); local ground = display.newRect(20,400 ,600, 50); physics.addBody(ground, "static"); function onCollision( event ) left = event.object1; right = event.object2; if ( event.phase == "began" ) then if((left.myName == "rect") and (right.myName == "obj")) then print("herro passes dynamic object") end end end Runtime:addEventListener( "collision", onCollision )
i wanna my red hero penetrate green object, and give me message on console. green must by always in the some place.
Any ideas?
You can use the isSensor property; it makes objects detect collisions but not respond to them:
obj.isSensor = true
If you want the red object to pass through the green one then you will need to set the collision filters for the objects.
Also, if you’re not wanting the green box to move then you can change its body type from dynamic to kinematic (http://docs.coronalabs.com/api/type/Body/bodyType.html)
[edit]
A quick play with your code…
local physics = require("physics") physics.start() physics.setGravity( 0, 9.8 ) local hero = display.newRect(200,200 ,40, 50); hero.myName = "rect" hero:setFillColor( 1, 0, 0 ) physics.addBody(hero, "dynamic"); local obj = display.newRect(200,300 ,40, 50); obj.myName = "obj" obj:setFillColor( 0, 1, 0 ) physics.addBody(obj, "kinematic"); obj.isSensor = true local ground = display.newRect(20,400 ,600, 50); physics.addBody(ground, "static"); function onCollision( event ) if ( event.phase == "began" ) then if((event.target.myName == "rect") and (event.other.myName == "obj")) then print("herro passes dynamic object") end end end hero:addEventListener( "collision", onCollision )
working greate
Thanks a lot guys
From the way it sounds, you want an object to be dynamic but stay in place?
If not, please explain some more.
Some code:
local physics = require("physics") physics.start() physics.setGravity( 0, 9.8 ) local hero = display.newRect(200,200 ,40, 50); hero.myName = "rect" hero:setFillColor( 1, 0, 0 ) physics.addBody(hero, "dynamic"); local obj = display.newRect(200,300 ,40, 50); obj.myName = "obj" obj:setFillColor( 0, 1, 0 ) physics.addBody(obj, "dynamic"); local ground = display.newRect(20,400 ,600, 50); physics.addBody(ground, "static"); function onCollision( event ) left = event.object1; right = event.object2; if ( event.phase == "began" ) then if((left.myName == "rect") and (right.myName == "obj")) then print("herro passes dynamic object") end end end Runtime:addEventListener( "collision", onCollision )
i wanna my red hero penetrate green object, and give me message on console. green must by always in the some place.
Any ideas?
You can use the isSensor property; it makes objects detect collisions but not respond to them:
obj.isSensor = true
If you want the red object to pass through the green one then you will need to set the collision filters for the objects.
Also, if you’re not wanting the green box to move then you can change its body type from dynamic to kinematic (http://docs.coronalabs.com/api/type/Body/bodyType.html)
[edit]
A quick play with your code…
local physics = require("physics") physics.start() physics.setGravity( 0, 9.8 ) local hero = display.newRect(200,200 ,40, 50); hero.myName = "rect" hero:setFillColor( 1, 0, 0 ) physics.addBody(hero, "dynamic"); local obj = display.newRect(200,300 ,40, 50); obj.myName = "obj" obj:setFillColor( 0, 1, 0 ) physics.addBody(obj, "kinematic"); obj.isSensor = true local ground = display.newRect(20,400 ,600, 50); physics.addBody(ground, "static"); function onCollision( event ) if ( event.phase == "began" ) then if((event.target.myName == "rect") and (event.other.myName == "obj")) then print("herro passes dynamic object") end end end hero:addEventListener( "collision", onCollision )
working greate
Thanks a lot guys