angle measurement for object foward backward movement

Aloha! 

At the moment in my game I have two objects - one at the center of the screen and the other connected with a pivot joint to the first object. the second object moves around the first object all the time. my goal is to make the moving object move foward and backward on touch event depends on the angle of the object. how do I measure it’s angle and make it move at the same direction while it continue to spin around the center?

Thank.

Itay

Hi Itay,

I think this would be better solved with an illustration or diagram that shows what you’re doing, how the objects relate, and how you want things to move. Can you provide that please?

Brent

Is this the kind of thing you’re talking about?

https://www.youtube.com/watch?v=lUEcyNnHnuo&feature=youtu.be

If so, you can do this in just a few lines of code w/ SSK2 (lite or PRO):

require "ssk2.loadSSK" \_G.ssk.init( {} ) ssk.easyInputs.oneTouch.create( nil, { debugEn = true } ) local function enterFrame( self ) if( self.isRotating ) then self.rotation = self.rotation + 90 \* ssk.getDT() / 1000 ssk.actions.move.forward( self, { rate = 0 } ) else ssk.actions.move.forward( self, { rate = 100 } ) end end local dude = ssk.display.newImageRect( nil, centerX, centerY, "dude.png", { size = 80, isRotating = true, enterFrame = enterFrame }) function dude.onOneTouch( self, event ) if(event.phase == "began") then self.isRotating = false elseif( event.phase == "ended") then self.isRotating = true end end; listen("onOneTouch", dude)

Link to code (not including SSK2 of course):

https://github.com/roaminggamer/RG_FreeStuff/raw/master/SSK2/forums_help/forwardmover.zip

PS - I second the request for a drawing or something to help clarify your question.

maybe something like this? (assumes 240x320 content)

local physics = require("physics") physics.start() local radius = 60 local obj1 = display.newCircle(120, 160, 10, 10) physics.addBody(obj1, "static") local obj2 = display.newCircle(120+radius, 160, 10, 10) physics.addBody(obj2, "dynamic") local joint = physics.newJoint("pivot", obj1, obj2, obj1.x, obj1.y) display.newRect(40, 40, 40, 40):addEventListener("tap", function() radius=math.max(radius-5, 30) end) display.newRect(200, 40, 40, 40):addEventListener("tap", function() radius=math.min(radius+5, 100) end) Runtime:addEventListener("enterFrame", function()   local theta = math.rad(joint.jointAngle)   obj2.x, obj2.y = obj1.x + radius \* math.cos(theta), obj1.y + radius \* math.sin(theta) end)

Hi dave, i’ts almost whats I need for my game. the only thing left for me is to use a touch event and not the tap one. when the player touch and hold it moves foward if not, it moves backward. Thanks!

i’d suggest opening a new topic for help with touch events

Hi Itay,

I think this would be better solved with an illustration or diagram that shows what you’re doing, how the objects relate, and how you want things to move. Can you provide that please?

Brent

Is this the kind of thing you’re talking about?

https://www.youtube.com/watch?v=lUEcyNnHnuo&feature=youtu.be

If so, you can do this in just a few lines of code w/ SSK2 (lite or PRO):

require "ssk2.loadSSK" \_G.ssk.init( {} ) ssk.easyInputs.oneTouch.create( nil, { debugEn = true } ) local function enterFrame( self ) if( self.isRotating ) then self.rotation = self.rotation + 90 \* ssk.getDT() / 1000 ssk.actions.move.forward( self, { rate = 0 } ) else ssk.actions.move.forward( self, { rate = 100 } ) end end local dude = ssk.display.newImageRect( nil, centerX, centerY, "dude.png", { size = 80, isRotating = true, enterFrame = enterFrame }) function dude.onOneTouch( self, event ) if(event.phase == "began") then self.isRotating = false elseif( event.phase == "ended") then self.isRotating = true end end; listen("onOneTouch", dude)

Link to code (not including SSK2 of course):

https://github.com/roaminggamer/RG_FreeStuff/raw/master/SSK2/forums_help/forwardmover.zip

PS - I second the request for a drawing or something to help clarify your question.

maybe something like this? (assumes 240x320 content)

local physics = require("physics") physics.start() local radius = 60 local obj1 = display.newCircle(120, 160, 10, 10) physics.addBody(obj1, "static") local obj2 = display.newCircle(120+radius, 160, 10, 10) physics.addBody(obj2, "dynamic") local joint = physics.newJoint("pivot", obj1, obj2, obj1.x, obj1.y) display.newRect(40, 40, 40, 40):addEventListener("tap", function() radius=math.max(radius-5, 30) end) display.newRect(200, 40, 40, 40):addEventListener("tap", function() radius=math.min(radius+5, 100) end) Runtime:addEventListener("enterFrame", function()   local theta = math.rad(joint.jointAngle)   obj2.x, obj2.y = obj1.x + radius \* math.cos(theta), obj1.y + radius \* math.sin(theta) end)

Hi dave, i’ts almost whats I need for my game. the only thing left for me is to use a touch event and not the tap one. when the player touch and hold it moves foward if not, it moves backward. Thanks!

i’d suggest opening a new topic for help with touch events