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:
local function distanceChecker()if distanceTravelled > [[insert number]] thenplayer:play('stumble and trip animation')endRuntime:addEventListener("something that fires every frame", distanceChecker)[/code]If the distance travelled from one frame to the next meets the specified number, it will trigger the player to do something like stumble, or stop halfway, etc. I'm fairly new to Corona, so I'm a little unsure if this is a good method to use, or how the code should look exactly. If anyone out there can help me it would be much appreciated.Much thanks,Steven [import]uid: 79394 topic_id: 16573 reply_id: 316573[/import]
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
[import]uid: 88628 topic_id: 16573 reply_id: 62021[/import]
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:
local physics = require("physics")physics.start()physics.setGravity(0, 0) local player = display.newCircle(384,1000,20)physics.addBody(player,"kinematic")--Player movement functionlocal 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 endplayer:addEventListener( "touch", onTouch )--Enemy spawn functionlocal 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}) endtimer.performWithDelay(850,enemySpawn,0) --Collision function local function onPlayerCollision() player:setFillColor(255,0,0) print("collided with enemy")endplayer:addEventListener("collision",onPlayerCollision)[/code] [import]uid: 79394 topic_id: 16573 reply_id: 62097[/import]