I have a draggable object (my player) that must be dragged past spawning enemies to progress in the game. The problem is, if the person playing the game "swipes" the draggable object very quickly, the player actually passes through enemies without triggering any collisions. Is there any way to sense when the draggable object is being swiped, or zipped from one point to another? I'm thinking of something like:
1 2 3 4 5 | local function distanceChecker() if distanceTravelled > [[insert number]] then player:play('stumble and trip animation') end Runtime:addEventListener("something that fires every frame", distanceChecker) |
All I know is that setting a physics object to isBullet makes the collisions more accurate
myBody.isBullet = true
read this
(http://blog.anscamobile.com/2011/08/solutions-to-common-physics-challenges/)
you can try using a touch joint to move and set the frequency or dampening (not sure which one) to drag slower
find the Debug Draw sample in templates->physics
Thanks for putting that out there, ernests.
I tried using .isBullet, but unfortunately it doesn't make a difference.
To anyone out there, if you can change the following code so the circle turns red even with the fastest swipe, you will have solved my problem. Here's my test code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | local physics = require("physics") physics.start() physics.setGravity(0, 0) local player = display.newCircle(384,1000,20) physics.addBody(player,"kinematic") --Player movement function local function onTouch( event ) local player = event.target local phase = event.phase if "began" == phase then -- Make target the top-most object local parent = player.parent parent:insert( player ) display.getCurrentStage():setFocus( player ) player.isFocus = true -- Store initial position player.x0 = event.x - player.x player.y0 = event.y - player.y elseif player.isFocus then if "moved" == phase then player.x = event.x - player.x0 player.y = event.y - player.y0 end end return true end player:addEventListener( "touch", onTouch ) --Enemy spawn function local function enemySpawn (event) local enemy = display.newRect(20,20,300,100) enemy.x = -300 enemy.y = 512 physics.addBody(enemy,"dynamic",{isSensor = true}) enemy.isSensor = true transition.to(enemy, {time = 3000, delay = 0, x = enemy.x + 1368, onComplete=function() enemy :removeSelf() end}) end timer.performWithDelay(850,enemySpawn,0) --Collision function local function onPlayerCollision() player:setFillColor(255,0,0) print("collided with enemy") end player:addEventListener("collision",onPlayerCollision) |