How do I set position of a dynamic object?

I’m trying to work around my issue here:

By manually creating the objects, so I’d be able to enable/disable as required and can set their group and mask in the editor. However, as was noted here I cannot set the position of a dynamic object, I have to disable to collision object first.

My problem is that when you enable the collision object again it snaps back to where it was. I wrote little function:

local function setPos(id, x, y)
	msg.post(id .. "#collisionobject", "disable")
	go.set_position(vmath.vector3(x, y, 0), id)
	msg.post(id .. "#collisionobject", "enable")
end

Which ends up doing nothing. If I comment out the enable I can see it did move:

local function setPos(id, x, y)
	msg.post(id .. "#collisionobject", "disable")
	go.set_position(vmath.vector3(x, y, 0), id)
	-- msg.post(id .. "#collisionobject", "enable")
end

All I want to do is have a selection of objects of the same base object that can collide with each other. If I use a factory (and hence can set their starting position) there seems to be no group/mask combination that won’t stop the object colliding with itself and I can’t dynamically change the group/mask later. If I add them to the main.collection manually I can set the group/mask so that each object only collides with the other ones (as I effectively have several different base objects, only differing by group/mask) but I cannot set their starting position.

Beyond having to do all the physics manually, does anyone have a solution?

1 Like