Making an object move around a circle

I have a circle, and an object that i want moving around the circle. The object and the circle are joined using a pivot joint. I want the object to be moved using the accelerometer, as in when the user tilts the device to the right, the object moves clockwise. I have tried to change the gravity upon tilt as well as adding a force/impulse, but the object would continue to move even when friction is set to max. I have also tried to use some math (sin and cos), but I was not able to make it work. Please help and thanks. [import]uid: 82699 topic_id: 20996 reply_id: 320996[/import]

Hi!

It is pretty simple :

[lua]local originX,originY = 200,200 – Center position of the circle

local radius = 100 – Radius of the circle

local cosCounter = 0 – position of the object thats going to move around the circle
– each lap takes math.pi*2

function enterFrame()

object.x = math.sin(cosCounter)*radius + originX
object.y = math.cos(cosCounter)*radius + originY

cosCounter = cosCounter + 0.3 – speed of the object ( + is clockwise )
end[/lua]

About the accelerometer, you could just use the input value you are getting from the event, and use it to control the speed ( cosCounter ).

I haven’t tried the code , but it should work =) [import]uid: 103182 topic_id: 20996 reply_id: 82946[/import]

Thanks for the reply. I tried it with adjusting the cosCounter as follows:

if remote.yGravity > 0 then
cosCounter = cosCounter + 0.3 – speed of the object ( + is clockwise )
elseif remote.yGravity < 0 then
cosCounter = cosCounter - 0.3 – speed of the object ( + is clockwise )
end

The object does move, but it only moves by 0.3 (or whatever i change the value to) in each direction. It seems as though the pivot joint has a fixed rotation (which it doesn’t). Also it behaves in a weird way. The gravity is set to (0,0), but when I launch the simulator, the object starts from the top of the circle and quickly goes down but without going around it. In hybrid mode, I can see the line (starting from the center of the circle) go straight up for half the circle, and straight down to the whole circle.

I managed to make applyForce work with the accelerometer in the way I want to, but the tilts don’t feel natural which I’m worried might diminish the user experience. [import]uid: 82699 topic_id: 20996 reply_id: 82951[/import]

Thanks for the reply. I tried it with adjusting the cosCounter as follows:

if remote.yGravity > 0 then
cosCounter = cosCounter + 0.3 – speed of the object ( + is clockwise )
elseif remote.yGravity < 0 then
cosCounter = cosCounter - 0.3 – speed of the object ( + is clockwise )
end

The object does move, but it only moves by 0.3 (or whatever i change the value to) in each direction. It seems as though the pivot joint has a fixed rotation (which it doesn’t). Also it behaves in a weird way. The gravity is set to (0,0), but when I launch the simulator, the object starts from the top of the circle and quickly goes down but without going around it. In hybrid mode, I can see the line (starting from the center of the circle) go straight up for half the circle, and straight down to the whole circle.

I managed to make applyForce work with the accelerometer in the way I want to, but the tilts don’t feel natural which I’m worried might diminish the user experience. [import]uid: 82699 topic_id: 20996 reply_id: 82952[/import]

hi code work great but im struggling to set the cosCounter to the correct value to start moving my object from its current position. e.g. in my game a object flys onto screen and then when a certain distance from its target starts to move around it in a circle. At present my object jumps to the 0 position of cosCounter when I start the function.

Could you please tell me what value should be used as the starting point and how to achieve it.

[code]
local spinAround = function(self,yOffset,tDelta,targetY,targetX)

self.x = 0.8 * sinIt(cosCounter)*radius + targetX
self.y = cosIt(cosCounter)*radius + targetY
cosCounter = cosCounter - tDelta* 0.01 – speed of the object ( + is clockwise )
return
end

[/code] [import]uid: 118379 topic_id: 20996 reply_id: 93317[/import]