Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Joint shift due to collision
Started by pahuchiy Dec 25 2019 07:05 AM

1 reply to this topic
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

pahuchiy

[GLOBAL: userInfoPane.html]
pahuchiy
  • Observer

  • 26 posts
  • Corona SDK

The question is in the comments to the code.

local physics = require('physics')

physics.start()
physics.setGravity( 0, 0 )
physics.setDrawMode( "hybrid" )

local c1 = display.newRect( 100, 200, 40,40 )
local c2 = display.newRect( 100,400, 40, 400 )
c2.fill = {1,0,0}


physics.addBody( c1)
physics.addBody( c2)


physics.newJoint( "pivot", c1,c2,100, 210 )

-- Objects have the same x coordinate (x = 100)
-- Joint exactly in the middle of objects

timer.performWithDelay( 1000,function()
  physics.setGravity( 0, 5 )
  local static = display.newRect( 100, 400, 40, 40)
  physics.addBody( static, "static")
end )
--Now the top cube is a little to the right of the stick. Why? Did the coordinates of the joint change?
--I understand that this is due to a collision with a static object.
--This means you can’t create a new body if during creation it intersects with others?


[TOPIC: post.html]
#2

sporkfin

[GLOBAL: userInfoPane.html]
sporkfin
  • Contributor

  • 711 posts
  • Corona SDK

I can't test your code at the moment but generally if you create one physics body inside of another, Box2D will resolve the the physics world by pushing the new body to a location outside of the first body.  

 

This is normal behavior, however, depending on what you are trying to achieve you can turn the first body into a sensor or use collision filters to allow both bodies to occupy the same physics space.  I hope that helps.




[topic_controls]
[/topic_controls]