Have an object move faster than the finger

I am trying to have an object move faster than the finger that is controlling it but have stumbled upon a problem with the initial touch.

Below is the code I am using for regular movement.

local function onTouch(event)  
  
 if event.phase == "began" then  
 player.isFocus = true   
 player.x0 = event.x - player.x  
 player.y0 = event.y - player.y  
 elseif player.isFocus then  
 if event.phase == "moved" then  
 player.x = event.x - player.x0  
 player.y = event.y - player.y0  
 keepOnScreen(player)  
 elseif phase == "ended" or phase == "cancelled" then  
 player.isFocus = false  
 end  
 end  
  
 return true  
end  

For having the object move faster than the finger controlling it, I simply multiply the result of the two calculations below with a number greater than 1:

player.x = (event.x - player.x0)\*1.25  
player.y = (event.y - player.y0)\*1.25  

This does make the object move faster than the finger but upon the initial touch, the object will jerk to the right. The longer the finger is from the object, the greater the initial jerk.

Can anyone see what I am doing wrong? [import]uid: 99737 topic_id: 24699 reply_id: 324699[/import]

The reason why it’s jerking is because of the *1.25 . Your player is literally teleporting from it’s current spot to whatever it is multiplied by 1.25.

Here’s an example which you probably already know:
player.x = 200
–let’s say you click at 300 x
event.x = 300

new player.x = 300 - (300-200) => player.x = 200 ==> new player.x = 200 * 1.25 which is 250. so it will move your guy from 200 to 250 which is why it seems like a jerk. another problem i see with your code is that it will only be called once on moved, it wont actually make the guy go faster if you havent released your finger and touched again. what are you trying to accomplish exactly? some kinda snake control but have him move faster? or however you move your finger you want your player to move in that exact way only faster? [import]uid: 77199 topic_id: 24699 reply_id: 100102[/import]

agreed with hatethinkingofnames.

If you want it to be less jerky, you could do something like:

transition.to(player, {time=1, x=(event.x - player.x0), y=(event.y - player.y0), transition=easing.inOutExpo})  

instead of simply setting player.x = …

What is the desired effect if the finger is pressed directly on top of the player? should it only start to run away once you move it? Or should it move out of the way immediately? [import]uid: 118390 topic_id: 24699 reply_id: 100108[/import]

“or however you move your finger you want your player to move in that exact way only faster?”

Yes, that is what I am trying to accomplish.

I am making a shoot’em up and I want the players character to reach the edge of the screen faster than the finger - much like Cave does in their games.
This way the player doesn’t have to move his finger about as much.

It seems to me it would involve tracking the distance between the current and the previous event.x and then move the players character based on that.

What are your thoughts? [import]uid: 99737 topic_id: 24699 reply_id: 100110[/import]

Can you show me an exact sample of it in a game or tell me a game name? I looked up games from Cave but they have a ton of games unless I got the wrong one.

At work atm but your thing seems interesting, hope I can work on it tonight [import]uid: 77199 topic_id: 24699 reply_id: 100180[/import]

I think it shows best in Espgaluda II. There is a lite version.

In most other shoot’em up’s it feels more like you are dragging the character around than moving it, but I didn’t really notice it until I tried this game.

[import]uid: 99737 topic_id: 24699 reply_id: 100230[/import]

The code isnt complete but this might help you enough to get started, I’ll try to work on it when I can again, got home at 5;33 this morning so I only got to work on it a few hours later when I woke up a little. I could only look at the amazing trailer for that game and not play it since I dont have any device so let me know what changes you would like for it and what’s not the way you’d want. Also note that I dont have time to clean up the code Im really sorry for the inconvenience but i thought itd be better to post it now instead of 12 hours later or whenever I get home. Ill clean it up and work on it more so it work closers to what you want, just gimme some feedback and hope you understand it, let me know if you need anything or any explanation.

[code]
local spawnTrue = true;
display.setStatusBar( display.HiddenStatusBar )
local physics = require “physics”
physics.start()
physics.setDrawMode ( “hybrid” )
–physics.setDrawMode ( “normal” )
physics.setGravity( 0, 0 )

system.activate( “multitouch” )

local leftwall = display.newRect(0, 0, 1, display.contentHeight )
local rightwall = display.newRect( display.contentWidth, 0, 1, display.contentHeight )
local ceiling = display.newRect( 0, 0, display.contentWidth, 1 )

physics.addBody(leftwall, “static”, { bounce = 0.1 } )
physics.addBody(rightwall, “static”, { bounce = 0.1 } )
physics.addBody(ceiling, “static”, { bounce = 0.1 } )
local ground = display.newRect( 0, 0, 320, 50)
ground:setReferencePoint( display.BottomLeftReferencePoint )
ground.x, ground.y = 0, 540

– local groundShape = { -240,-20, 240,-20, 240,20, -240,20 }
– local ground = display.newRect( 100, 100, 0, 0 )
physics.addBody( ground, “static” )
movez = 0
local myText = display.newText("", 150, 150, native.systemFont, 16)
local player = display.newRect( 150, 150, 50, 50 )
physics.addBody( player, “dynamic” )
player.myName = “player”

local function stopPlayer()
player:setLinearVelocity(0, 0)
end

local function movePlayer( event )

movex = event.x
movey = event.y
movetx = event.x - player.x
movety = event.y - player.y
vmax = 100
– movez^2 = movetx^2 + movety^2

moves = (movetx*movetx + movety*movety)

sfactor = (vmax^2/moves)^0.5
velx = movetx * sfactor
vely = movety * sfactor

travelTime = 1000 * (moves^0.5)/100

move1 = math.pow(movetx, 2)
move2 = math.pow(movety, 2)
movez = math.sqrt(move1 + move2)
testx = player.x - movetx
testy = player.y - movety

myText.text = movez

player:setLinearVelocity(velx*3, vely*3);

if event.phase == ‘ended’ then
stopPlayer()
end
– if event.phase == “moved” then
– transition.to( player, { time=travelTime, x=movex, y=movey } )
– end
end
Runtime:addEventListener( “touch”, movePlayer )
[/code] [import]uid: 77199 topic_id: 24699 reply_id: 100401[/import]

Thank you. I will have a look at it later. Too busy right now. [import]uid: 99737 topic_id: 24699 reply_id: 100825[/import]