My intent in the code below was to touch the right side of the screen and have the ship object’s velocity slowly increase (accelerate) until it reaches a max velocity of 200. That velocity would be held until the touch event ends.
What is happening is that when the screen is touched, the ship/screen freezes, the print statement counts off the velocity from 1 - 200, and only after vx reaches 200 does the ship/screen unfreeze and the ships moves at 200.
Maybe I don’t understand exactly how the While-Loop works? Can someone help me with a method for gradually increasing the speed of my ship up to a defined maximum?
[lua]local onScreenTouch = function( event )
if event.phase == “began” then
if event.x > halfW then
vx, vy = ship:getLinearVelocity( )
while vx ~= 200 do
ship:setLinearVelocity( vx, vy )
vx = vx + 1
print("velocityX : "…vx)
end
else
ship:setLinearVelocity( -100, vy )
end
elseif event.phase == “ended” then
ship:setLinearVelocity( 0, vy )
end
end[/lua] [import]uid: 146966 topic_id: 30959 reply_id: 330959[/import]
[import]uid: 52491 topic_id: 30959 reply_id: 123860[/import]