rotate phyics with group

Hi guys,

I’m trying to rotate an object group. All of the objects in the groups have separate bodies. 

When I tried rotating the complete group, my physic layers on my objects didn’t rotate as I’d wanted them to. Instead, they rotated over their own anchor point.

How could I fix this?

Kind regards

Bram

Hey bramvbilsen,

physics objects live in their own world in some means.

I would suggest looping through the group and reposition the objects accordingly.

local function vecRotateDeg(x, y, angle) angle = angle\*math.pi/180 local fCos = math\_cos(angle) local fSin = math\_sin(angle) return fCos\*x - fSin\*y, fCos\*y + fSin\*x end local function rotatePhysicsGroup(group, angle) local groupRotationDif = angle - group.rotation group.rotation = angle for i=1, group.numChildren do local object = group[i] object.x, object.y = vecRotateDeg(object.x, object.y, groupRotationDif) end end rotatePhysicsGroup(group, 45)

You can work this out further, like only applying this to physic objects. But that is another story.

Hope that helps :slight_smile:

Hey bramvbilsen,

physics objects live in their own world in some means.

I would suggest looping through the group and reposition the objects accordingly.

local function vecRotateDeg(x, y, angle) angle = angle\*math.pi/180 local fCos = math\_cos(angle) local fSin = math\_sin(angle) return fCos\*x - fSin\*y, fCos\*y + fSin\*x end local function rotatePhysicsGroup(group, angle) local groupRotationDif = angle - group.rotation group.rotation = angle for i=1, group.numChildren do local object = group[i] object.x, object.y = vecRotateDeg(object.x, object.y, groupRotationDif) end end rotatePhysicsGroup(group, 45)

You can work this out further, like only applying this to physic objects. But that is another story.

Hope that helps :slight_smile: