problem with angle and a line

What happens if you add a

return true 

at the end of the function? I guess it’s superfluous for a Runtime listener, but if your object, e , doesn’t trap the touch, the catch-all one will also fire. I don’t know if this will lead to the problem you’re seeing, but it’s worth a try.

no it’s the same and it’s worse at the angle of interpretation by GetAngle :unsure:

yes !

It becomes clearer. When i comment the function (e.indicate) in the snippet below.

e.touch=function(ev) if ev.phase == "began" then previousTime=ev.time myTimer=timer.performWithDelay(2000, e.energy, -1) --e.indicate(ev) elseif ev.phase=="moved" then timeMiddle = ev.time-previousTime elseif ev.phase == "ended" then line.alpha=0 timer.cancel(myTimer) timePassed=ev.time-previousTime if timePassed \> 200 then lineardamping=30-timePassed/40 force=timePassed\*10000000000 else lineardamping=0 end e.body.linearDamping=lineardamping e.body:applyForce(((ev.x - e.body.x )\*force), ((ev.y-e.body.y)\*force),e.body.x,e.body.y) end end

It work perfectly !

What i don’t understand is why this function prevents my code run ? have you an idea about that ?

Thanks

 e.indicate=function(ev) line.alpha=0 lineY=ev.y value=lineY-line.y transition.to(line, {time=500,yScale=value,alpha=.5}) end

here is an example that you could test at home

i would in effect scale a line according to the position of event and orientate the line according to the event.

the problem i when i add these line, my function getAngle don’t work properly…could you tell me why

line.yScale=event.y-cy

the snippet :

--main.lua local player={} player.body=display.newCircle(200,200,10) line=display.newRect(50,50,2,2) --line who the begin is the player and the end is the event line:setFillColor(1,1,1) line.anchorY=1 function playerInMovement() xposMov=math.random(0,400) yposMov=math.random(0,400) transition.to(player.body, {time=900,x=xposMov,y=yposMov}) transition.to(player.body, {delay=900,time=400,x=50,y=50}) end timer.performWithDelay(1800,playerInMovement,-1) function getAngle(x1,y1,x2,y2) local Angle= math.atan2(y2 - y1, x2 - x1) return math.deg(Angle) end Runtime:addEventListener("touch",function(event) if event.phase == "began" then elseif event.phase == "moved" then local cx, cy = player.body:localToContent(0, 0) line.x=cx line.y=cy line.yScale=event.y-cy local angle = getAngle(cx,cy,event.x,event.y) line.rotation = angle+90 elseif event.phase == "ended" then end end)

Finded ! if this could help somebody :slight_smile:

this was simple…yScale could be positive or negative depending of event !

local player={} player.body=display.newCircle(200,200,10) line=display.newRect(50,50,2,2) line:setFillColor(1,1,1) line.anchorY=1 function playerInMovement() xposMov=math.random(0,400) yposMov=math.random(0,400) transition.to(player.body, {time=900,x=xposMov,y=yposMov}) transition.to(player.body, {delay=900,time=400,x=50,y=50}) end timer.performWithDelay(1800,playerInMovement,-1) function getAngle(x1,y1,x2,y2) local Angle= math.atan2(y2 - y1, x2 - x1) return math.deg(Angle) end Runtime:addEventListener("touch",function(event) if event.phase == "began" then elseif event.phase == "moved" then local cx, cy = player.body:localToContent(0, 0) local angle = getAngle(cx,cy,event.x,event.y) line.rotation = angle+90 line.x=cx line.y=cy if event.y \> line.y then line.yScale=event.y-cy else line.yScale=cy-event.y end elseif event.phase == "ended" then end end)