How do I detect an object crosses a line?

0 favourites
  • 8 posts
From the Asset Store
solution for games like "fruit ninja" and drawing applications
  • Hi##

    I need to check that a disc has crossed over the barrier which I am srawing using the canvas between 2 other discs, and am not sure how to achieve this?

    I dynamically draw the barrier across the 2 discs with the larger Y values out of the 3 discs, and the user has to get the disc between the other 2 discs, without touching them.

    Any advice appreciated.

    SM

  • Sorry, bad image...

  • I would first try creating a sprite just for overlap detection. Just change the size and rotation of that sprite at runtime between the 2 barriers, then check if your player disc is overlapping that sprite. That sprite would be invisible in the real game though.

    If the disc is going at high speeds then you could move the player's disc with the Bullet behavior and enable stepping mode so you can do more fine grained overlap tests.

    If you need the disc to only be able to cross in a certain direction, like crossing over the finish line in a racing game, then that gets a lot more complicated, but still doable. It would require you to model the sprite positions as vectors and compute the dot product. Let me know if you need this and I can attempt to elaborate on it.

  • Hi

    My disc is physics Xs based. I created a sprite square without physics, and am stretching it between the 2 discs at the required angle. The issue is, my ‘is overlapping’ isn’t firing?! Is it because one is physics based and one isnt? Does stepping and bullet work between physics and non physics?

    Thanks

    SM

  • Lol, I was disabling collisions on start of layout

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Oh haha gotcha. So did you get it to work then?

  • Hi

    Yes thanks. Couple of Boolean to check the initial collision - and then the end of the collision means it passed all the way through.

    Regards

    SM

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)