playMaker

Author Topic: touch drag 2d object with physics  (Read 1862 times)

haikugames

  • Playmaker Newbie
  • *
  • Posts: 25
touch drag 2d object with physics
« on: March 07, 2014, 10:35:24 PM »
I have been making some minigames to get more familiar with Playmaker.  One that I am making is a simple wooden block sliding game for iOS / Android.  You try to slide one block out of the puzzle. (something like this http://a5.mzstatic.com/us/r30/Purple/v4/93/40/4b/93404b54-3d80-aa59-0f75-dab93180bb14/screen320x480.jpeg

My question is what advice can you give me for moving the wooden blocks?  I tried setting the position of the block to follow my finger by getting drag info, doing screen to world point, and setting the block at that position.  This works great if there's no collisions.  The issue is I need to stop the block if it hits other blocks or walls, etc. 

I'd just set a hard floor and ceiling for the x or y position, except this can get quite dynamic if other blocks are moving in front of it. 

I tried to solve this by adding walls which were Rigidbodies, but if I drag quickly, I can still move the block over the walls.  The reason, I believe, is that I am just setting the block's position, so it only checks for collision every frame. 

I think I can better use physics by adding force to the block as I drag, but I want it to closely follow the player's finger. 

Any advice appreciated :)

Thanks!
« Last Edit: March 09, 2014, 09:56:52 PM by haikugames »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: touch drag 2d object with physics
« Reply #1 on: March 11, 2014, 07:40:18 AM »
Hi,

 I don't think you should go for physics here and but more with simple triggers and some math.

 However you can increase your physics timestep and iteration ( in the Unity physics settings) and your collisions are going to be a lot more reliable.

bye,

 Jean