Thanks for this lengthy tutorial, Brent! I think I need to restart on my character movement, to fix things up a little.
I also placed the code of your tutorial in a stand-alone example and the same happens.
https://www.youtube.com/watch?v=a4tkG919eCI&feature=youtu.be
@Brent, I took apart the sample the “InputDevices” sample and I was able to combine it with the sample I sent you, and there were no issues when I used frame by frame movement. However, I could not get it to work with linear velocity. How could I achieve this?
I looked at the code and you’re never “stopping” linear velocity. Why not just use the example in the tutorial? I tested it with linear velocity and it works just fine. No issues at all in my tests.
Brent
Can you send me a zip file of one of your tests? In case, something is wrong on my side.
Just copy the one from the tutorial, under “Virtual Directional Pad” > “Physics-Based Movement”. It’s like 45 lines total and it’s the same test I used to write the tutorial.
Is setting it to 0, 0 not stopping it? The code is in the ended phase. PS (I am talking about the first zip file)
Yes 0,0 stops it, but it depends where you put it. Really, the tutorial solves it. I can’t advise you use the “InputDevice” model with physics any longer.
Brent
Ok, here is what I have now:
local function move( event ) if ( event.phase == "began" ) then -- Register movement if ( event.target.isPressed == false ) then if ( event.target.ID == "left" ) then character:setLinearVelocity( -100, 0 ) elseif ( event.target.ID == "right" ) then character:setLinearVelocity( 100, 0 ) end end event.target.isPressed = true elseif ( event.phase == "moved" ) then -- Check if touch moves inside rectangular bounds if ( event.x \> event.target.contentBounds.xMin+4 and event.x \< event.target.contentBounds.xMax-4 and event.y \> event.target.contentBounds.yMin+4 and event.y \< event.target.contentBounds.yMax-4 ) then event.target:dispatchEvent( { name="touch", phase="began", target=event.target } ) -- Else, dispatch an "ended" event else event.target:dispatchEvent( { name="touch", phase="ended", target=event.target } ) end elseif ( event.phase == "ended" and event.target.isPressed == true ) then -- Stop movement event.target.isPressed = false character:setLinearVelocity(0,0) end return true end
When I hold the button down and then drag out of its area the character continues moving.
That is why I asked for a zip file for your test because right now, I can’t find anything different between my code and the tutorial.
OK, here’s my “main.lua” file. Of course you’ll need to substitute in your button images…
Emmm… There’s no file here.
…
I have confirmed, it also occurs on your main.lua as well.
https://www.youtube.com/watch?v=Ff7Uq8q-R30&feature=youtu.be
Although this is not specifically slide-off, this also sometimes occurs when I click on the button, hold, and drag out of it.
I’m sorry, but the Input Devices sample is the only directional key that does not give me any problems. But the usage of frame-by-frame movement with physics is sloppy and unsafe…
OK, you’re right, back to the drawing board… I was able to get the tutorial code to “keep moving” with a super-fast slide-off. I know why it’s happening, but I need to figure out a solution.
Thank you. I was beginning to get frustrated because I was sure I had done everything as you asked in the tutorial.
Hi, Brent, I just wanted to let you know that even though the tutorial was taken down, it is still accessible by this link:
https://docs.coronalabs.com/tutorial/events/continuousActions/index.html
Just to let you know.
Of course, when it is fixed the new one will replace it.
Also, when do you believe you will have the tutorial fixed? Not to rush you, but just to get an estimate, as I start 9th grade this Monday, and I am sure you are busy with other things.
The improved version will be ready before Monday.