[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]

Rotate an object in clockwise direction by circling around the object? Started by fazilreyaz May 18 2018 11:40 PM

2 replies to this topic
rotate rotation circling touch

Best Answer ldurniat , 19 May 2018 - 04:04 AM

Try replace line

` t.rotation = t.rotation - rotationAmt`

with

```if rotationAmt < 0 then

t.rotation = t.rotation - rotationAmt

end ```

ldurniat

[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

fazilreyaz

[GLOBAL: userInfoPane.html]
fazilreyaz
• Enthusiast

• 67 posts
• Corona SDK

Hello There!

I want to rotate an object only in clockwise direction not in anti clockwise direction and it should stop after few complete rotations.

Here is my code:

```local circle = display.newImageRect( "stearing.png", 158, 158 )
circle.x = display.contentWidth / 2
circle.y = display.contentHeight / 2

local function rotateObj(event)
local t = event.target
local phase = event.phase

if (phase == "began") then
display.getCurrentStage():setFocus( t )
t.isFocus = true

t.x1 = event.x
t.y1 = event.y

elseif t.isFocus then
if (phase == "moved") then
t.x2 = event.x
t.y2 = event.y

angle1 = 180/math.pi * math.atan2(t.y1 - t.y , t.x1 - t.x)

angle2 = 180/math.pi * math.atan2(t.y2 - t.y , t.x2 - t.x)

rotationAmt = angle1 - angle2

t.rotation = t.rotation - rotationAmt

t.x1 = t.x2
t.y1 = t.y2

elseif (phase == "ended") then

display.getCurrentStage():setFocus( nil )
t.isFocus = false
end
end

return true
end

Above code works for both the directions i.e. clockwise and anti clockwise.

So, I want to know what changes I have to make to achieve the desired task.

Any help would be highly appreciated.

Thanks,

[TOPIC: post.html]
#2

ldurniat

[GLOBAL: userInfoPane.html]
ldurniat
• Contributor

• 403 posts
• Corona SDK

Try replace line

` t.rotation = t.rotation - rotationAmt`

with

```if rotationAmt < 0 then

t.rotation = t.rotation - rotationAmt

end ```

ldurniat

[TOPIC: post.html]
#3

fazilreyaz

[GLOBAL: userInfoPane.html]
fazilreyaz
• Enthusiast

• 67 posts
• Corona SDK

Try replace line

` t.rotation = t.rotation - rotationAmt`

with

```if rotationAmt < 0 then

t.rotation = t.rotation - rotationAmt

end ```

ldurniat

Perfect. Thank you so much.

[topic_controls]

[/topic_controls]