How do I put the flowers on the middle of the line

Get help using Construct 2

Post » Sat Mar 02, 2013 1:07 pm

Hi all

I've got a sample project here:

http://dl.dropbox.com/u/116137178/GamesDev/Intersect/Intersect.capx

If you click / touch anywhere it will spawn a wider hitbox area, which kind of widens the touch/click point. If that wider area overlaps a line, then it makes a flower where you have touched/clicked.

This isn't what I want, I want the flower to always be dead on the line. i.e. At the exact x,y point where the "WideHitBox" overlaps the "Line".

Is there any way to get this intersect info? Obviously c2 has it internally as it has detected the overlap in the first place.

B
20
S
6
G
2
Posts: 157
Reputation: 3,109

Post » Sat Mar 02, 2013 5:44 pm

You could use some coordinate geometry to calculate the slope of the Line (m1 = tan(Line.Angle)) and then get a perpendicular line (m2 = -1/m1) through the point (Touch.X, Touch.Y). And calculate the point of intersection between the two lines.

I had to refresh my memory on the maths - haven't done it in years :)
http://www.mathopenref.com/coordintersection.html

Capx: lineIntersect.capx (r120.2)

Maybe there's a better way?
B
54
S
28
G
18
Posts: 1,520
Reputation: 25,000

Post » Sat Mar 02, 2013 6:12 pm

elegant!
B
6
S
1
G
1
Posts: 70
Reputation: 702

Post » Sat Mar 02, 2013 8:53 pm

@ramones

Thank you so much! Now this game is working perfectly on touch. Before it was too hard to have to touch the line, hence adding the larger hit area. :)

It would be nice to see c2 have the "intersect point" exposed in a future build.. Ashley are you reading? :psilkc22013-03-02 20:54:08
B
20
S
6
G
2
Posts: 157
Reputation: 3,109


Return to How do I....?

Who is online

Users browsing this forum: Aserak2012, ManuelPerez and 22 guests