Smooth object moving with analog joystick?

Hi guys,

Ok I have yet another issue. I am using Mathew analog joystick (amazing piece of code!) and for the most part it works beautifully. I am trying to move a gun cross around the screen (Droid) using the joystick. I tried the following methods below.

The second method seems to be the best one (smoother) but there is a problem. If I stop moving my finger the gunCross keep moving (normal since there is deviation) I think it is probably because the joystick.lua do not return joyX =0 and joyY = 0 when the finger stop moving and there is deviation (joystick not at zero) I assume this but I am just newbie so do take this with a grain of salt…

I guess what I am after is a gunCross that moves smoothly with the joystick but stops when I stop moving my finger. By the way method 1 below work but is not very smooth and so not workable.

Hope someone call help with some pointers.

Thanks!

Mo.

ps: both methods are inside the “enterFrame” main()

  
-- METHOD 1  
local function moveGunCross1(event)  
  
if event.joyX ~= false then gunCross.x = screenW\*0.5 + event.joyX\*screenW\*0.5  
  
if event.joyY ~= false then gunCross.y = screenH\*0.5 + event.joyY\*screenH\*0.5  
  
....  
  
end  
  
-- METHOD 2  
local function moveGunCross2(event)  
  
if event.joyX ~= false then gunCross.x = gunCross.x + event.joyX\*5  
  
if event.joyY ~= false then gunCross.y = gunCross.y + event.joyY\*5  
  
.....  
  
end  
  

[import]uid: 49236 topic_id: 10350 reply_id: 310350[/import]

Hello guys,

I was wondering if someone can help me. I gave up on this issue but now I really need to find some kind of solution if possible.

I used both these great joystick codes:
http://developer.anscamobile.com/code/joystick
http://developer.anscamobile.com/code/simple-analog-stick-joystick-module

But unfortunately i was not able to make those analog joysticks move my gun cross image move smoothly on the screen. I am using on shooter game and i need a very good control of the gun cross. Method 1 is what i am using since it allow a better control but still not good enough. Basically when I move the joystick, the gun cross seems to not really follow (jerky movement)

Here my moveGunCross() code if anybody can help (Droid 1 with screen size 840X480 i believe)

THANKS!

Mo.

[code]

local function moveGunCross(event)
– MAKE SURE THE JOYSTICK IS MOVED…IF NOT IT RETURNS FALSE
if event.joyAngle ~= false then

– MAYBE I AM GOING TO FAST HERE.
– IF I DO NOT PUT THOSE NUMBERS (*427 AND *240) THEN
– THE GUN CROSS CANNOT REACH THE CORNER OF THE SCREEN OF COURSE…

calibX = event.joyX*427
calibY = event.joyY*240

else
calibX = 0
calibY = 0

end

gunCross.x = 427 +calibX
gunCross.y =240 + calibY

– CHECK FOR SCREEN CORNERS
if gunCross.x <= 0 then gunCross.x = 0 end
if gunCross.x >= 854 then gunCross.x = 854 end
if gunCross.y <= 0 then gunCross.y = 0 end
if gunCross.y >= 480 then gunCross.y = 480 end

end

[/code] [import]uid: 49236 topic_id: 10350 reply_id: 39552[/import]