[Solved]Get the position of where objects collide

0 favourites
  • 9 posts
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • Hello,

    I hope someone can help me. I'm drawing two lines in construct 2 and I want to spawn an object on the place where the 2 lines collide.

    Here is an image to make it clearer

    <img src="http://berryijmker.com/wp-content/uploads/2013/04/question.png" border="0" />

  • This is something I've had to deal with a number of times, and for the life of me I can't figure out how to do it. In the past I've resorted to certain objects being made up of nine different collision boxes to get something workable, which obviously isn't appropriate for every situation.

    If anyone can offer advice, I'd gladly listen to it, too.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • For these kinds of situations I decided to take math lessons. It is possible by using various formulae. You can formulate a line if you know positions of two dots on it. You can do this for two lines and then use the two functions in a mathematical expression to decide if the collide and where they collide.

    I am not there yet but I will surely go. In the meantime, it seems I will have to fiddle with various algorithms and values in them.

    For now, you could use a grid, and then check each square to see if they are colliding with both the lines, but this would cause problems with low-angle crossings. If you are going for angles closer to 90, it should give an estimation. Even if you got more than one crossing grid square, you could just find the middle point between their locations to increase accuracy.

  • good question, I deal with it using detectors, but if you find a solution, please, don't forget to say TELLES0808 on your reply =]

  • Biino

    Windwalker

    It's not terribly difficult to find the intersection point of 2 lines:

    You can use each "line" object's angle and position to determine its straight-line equation. From there, use the two equations to solve for the same x and y.

    Demo

    Capx

    This method will only work for straight lines. Unfortunately finding the intersection point of polygons is a bit outside my mathematical comfort zone... at least for now. It would be handy if there was a system expression for LastCollisionX and LastCollisionY. I don't know how difficult it would be to implement, but I do know it's a lot easier to detect if polygons collide rather than where.

    You'd be surprised how often math is used in creating games. Knowing basic algebra, trig, and geometry has helped me on several occasions. If you're interested in brushing up on the subject, there's a myriad of resources online.

  • zatyka thank you dude.

  • TELLES0808

    No problem. I would have added your user name to my last post, but for some reason I thought you were looking for a solution for polygons and not lines. Anyway, I hope my demo helped.

  • , thanks a lot, if you explain it like this it is indeed not that difficult haha :)

  • zatyka: thanks alot man, yesterday I was on math lesson to be able to find equations such as these :)

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