ilan Expert Licensed User Longtime User Apr 9, 2017 #1 hi everyone i need some help. i would like to know if a touch (x/y) is on the edge of an shape. now this is simple i just calculate if the touch is bigger or smaller then centerPoint + shape.width/3 now that is working BUT how do i do it if the the shape is rotated?? thanx Last edited: Apr 9, 2017
hi everyone i need some help. i would like to know if a touch (x/y) is on the edge of an shape. now this is simple i just calculate if the touch is bigger or smaller then centerPoint + shape.width/3 now that is working BUT how do i do it if the the shape is rotated?? thanx
ilan Expert Licensed User Longtime User Apr 9, 2017 #2 ok i solved it. i just calculate the distance between both points and if it is > then x i know the edges where touched. thanx anyway Last edited: Apr 9, 2017
ok i solved it. i just calculate the distance between both points and if it is > then x i know the edges where touched. thanx anyway
wonder Expert Licensed User Longtime User Apr 13, 2017 #3 ilan said: i just calculate the distance between both points Click to expand... Correct!
S sorex Expert Licensed User Longtime User Apr 14, 2017 #4 ilan said: ok i solved it. i just calculate the distance between both points and if it is > then x i know the edges where touched. Click to expand... won't this fail if the object is 90° or 270° rotated? then they are in line.
ilan said: ok i solved it. i just calculate the distance between both points and if it is > then x i know the edges where touched. Click to expand... won't this fail if the object is 90° or 270° rotated? then they are in line.
wonder Expert Licensed User Longtime User Apr 14, 2017 #5 I assumed that the complete algorithm would be: Step 1) Verify that: - userTouch(x, y) is inside Polygon[list(x,y)] Step 2) Verify that: - abs(distanceSquared(PolygonCenter, userTouch)) > abs(distanceSquared(PolygonCenter, SpecificPoint)) Last edited: Apr 14, 2017
I assumed that the complete algorithm would be: Step 1) Verify that: - userTouch(x, y) is inside Polygon[list(x,y)] Step 2) Verify that: - abs(distanceSquared(PolygonCenter, userTouch)) > abs(distanceSquared(PolygonCenter, SpecificPoint))
wonder Expert Licensed User Longtime User Apr 14, 2017 #6 Another algorihtm: Create two copies of one HitBox[A, B, C, D] and offset its position (center point) by: (-Polygon.halfWidth + HitBox.halfWidth) for box A, and (Polygon.halfWidth - HitBox.halfWidth) for box B. Verify: - UserTouch(x,y) is inside BoxA[] or inside BoxB[] Last edited: Apr 14, 2017
Another algorihtm: Create two copies of one HitBox[A, B, C, D] and offset its position (center point) by: (-Polygon.halfWidth + HitBox.halfWidth) for box A, and (Polygon.halfWidth - HitBox.halfWidth) for box B. Verify: - UserTouch(x,y) is inside BoxA[] or inside BoxB[]
ilan Expert Licensed User Longtime User Apr 14, 2017 #7 Another algorithm actually i solved it in a different way. i create 2 radius lengths: 1. movingRadius 2. rotatingRadius now what i do is i check the distance between touch position (x,y) and center position (x/y) of the object. if it is < movingRadius then object starts to move else if its < rotatingradius obj starts to rotate else (to far away from object = do nothing) like this its more user friendly to move an object. instead of having the touch to be inside the physicbody now it can be outside but still filter unwanted touches. the movingradius and rotatingradius has also a minimum value so if i use small objects you still get a good touch handling. so i set the radius according to the object width or height (the bigger of both) like: (lets take the rotating radius for example) Code: Copy rotatingradius = max(max(obj.width/2,obj1.height/2),vpW*0.1) so the rotating radius is the size of the bigger value between (obj.width/2 and obj.height/2) BUT NOT smaller then vpW*0.1 (10% of the screen width) this is how i do it in my new iSpriteKit game.
Another algorithm actually i solved it in a different way. i create 2 radius lengths: 1. movingRadius 2. rotatingRadius now what i do is i check the distance between touch position (x,y) and center position (x/y) of the object. if it is < movingRadius then object starts to move else if its < rotatingradius obj starts to rotate else (to far away from object = do nothing) like this its more user friendly to move an object. instead of having the touch to be inside the physicbody now it can be outside but still filter unwanted touches. the movingradius and rotatingradius has also a minimum value so if i use small objects you still get a good touch handling. so i set the radius according to the object width or height (the bigger of both) like: (lets take the rotating radius for example) Code: Copy rotatingradius = max(max(obj.width/2,obj1.height/2),vpW*0.1) so the rotating radius is the size of the bigger value between (obj.width/2 and obj.height/2) BUT NOT smaller then vpW*0.1 (10% of the screen width) this is how i do it in my new iSpriteKit game.
ilan Expert Licensed User Longtime User Apr 14, 2017 #8 sorex said: won't this fail if the object is 90° or 270° rotated? then they are in line. Click to expand... distance takes account both x and y axis so why should there be a problem if you have 90' or 270'? Code: Copy Sub distance(x1 As Float, x2 As Float, y1 As Float, y2 As Float) As Double Return Sqrt(Power(x2-x1,2)+Power(y2-y1,2)) 'simple distance calculation End Sub
sorex said: won't this fail if the object is 90° or 270° rotated? then they are in line. Click to expand... distance takes account both x and y axis so why should there be a problem if you have 90' or 270'? Code: Copy Sub distance(x1 As Float, x2 As Float, y1 As Float, y2 As Float) As Double Return Sqrt(Power(x2-x1,2)+Power(y2-y1,2)) 'simple distance calculation End Sub
wonder Expert Licensed User Longtime User Apr 14, 2017 #9 @ilan, whenever you can, always use DistanceSquared vs. Distance. https://gamedev.stackexchange.com/q...g-distance-squared-checks-rather-than-distanc
@ilan, whenever you can, always use DistanceSquared vs. Distance. https://gamedev.stackexchange.com/q...g-distance-squared-checks-rather-than-distanc
S sorex Expert Licensed User Longtime User Apr 14, 2017 #10 ilan said: distance takes account both x and y axis so why should there be a problem if you have 90' or 270'? Click to expand... I misinterpret this line "i just calculate the distance between both points and if it is > then x" I thought you only checked x position distance.
ilan said: distance takes account both x and y axis so why should there be a problem if you have 90' or 270'? Click to expand... I misinterpret this line "i just calculate the distance between both points and if it is > then x" I thought you only checked x position distance.