Find middle between two points
ericzingeler
Member Posts: 334
I'm trying to find the middle coordinates between touch 1 and touch 2. Any have a solution for this?
Thanks in advance!
Thanks in advance!
Answers
Solution:
PositionX = (Touch1.X + Touch2.X)/2
PositionY = (Touch1.Y + Touch2.Y)/2
Magnitude(touch1x-touch2x, touch1y-touch2y) /2
-C
One problem is that you never know which finger the player will touch the screen with first. So for example you cannot assume that touch2.X will be greater than touch1.X (and the same is true for touch.Y)
Here's what I would do:
Rule if touch.count >= to 2
-----Rule if touch2.X > touch1.x
---------change attribute game.middleX to (touch1.X + ((touch2.x-touch1.x)/2))
-----OtherWise
---------change attribute game.middleX to (touch2.X + ((touch1.x-touch2.x)/2))
-----Rule if touch2.Y > touch1.Y
---------change attribute game.middleY to (touch1.Y + ((touch2.Y-touch1.Y)/2))
-----OtherWise
---------change attribute game.middleY to (touch2.Y + ((touch1.Y-touch2.Y)/2))
-C
PositionX = (Touch1.X + Touch2.X)/2
PositionY = (Touch1.Y + Touch2.Y)/2
Works perfectly (any direction, + or -, doesn't matter). No need to add rules or per-fabricated functions in the expression editor.
(magnitude(point1.y - point2.y , point1.x - point2.x))/2