How to rotate physics body ?

rect2996.jpg?noCache=1426687119

How to rotate physics body ?

local physics = require "physics" physics.start() physics.setGravity( 0, 0 ) physics.setDrawMode( "hybrid" ) local myGroup = display.newGroup() local block = display.newRect(200,200,100,100) physics.addBody(block) myGroup:insert(block) myGroup.x = 150 myGroup.rotation = 45

Hi @martinlim520,

I don’t recommend rotating of groups that contain physics bodies (and absolutely you should not try to scale those groups). Instead, just rotate the actual physics object itself, and that should work fine.

Brent

rect3802.jpg?noCache=1426947108

How to keep same distance between two objects ? When I change object.x the distance between two objects will be different .

local block = display.newRect(100,100,200,20) block.rotation = 15 local block2 = display.newRect(100,200,200,20) block2.rotation = 15 local function move() block2.x = math.random(100,300) end timer.performWithDelay(1000,move,0)

@martinlim520 you should really mark Brent’s post as the answer and start a new thread because your second post is a new question entirely.

However, to answer your second question, all you need to do is add the same amount to the second object as the first.

Hi @martinlim520,

I don’t recommend rotating of groups that contain physics bodies (and absolutely you should not try to scale those groups). Instead, just rotate the actual physics object itself, and that should work fine.

Brent

rect3802.jpg?noCache=1426947108

How to keep same distance between two objects ? When I change object.x the distance between two objects will be different .

local block = display.newRect(100,100,200,20) block.rotation = 15 local block2 = display.newRect(100,200,200,20) block2.rotation = 15 local function move() block2.x = math.random(100,300) end timer.performWithDelay(1000,move,0)

@martinlim520 you should really mark Brent’s post as the answer and start a new thread because your second post is a new question entirely.

However, to answer your second question, all you need to do is add the same amount to the second object as the first.