User Tag List

Results 1 to 7 of 7

Thread: How to detect edge position that is directly facing Active?

  1. #1
    Clicker Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)

    Join Date
    Mar 2015
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question How to detect edge position that is directly facing Active?

    Hello,

    Is there a way to calculate the edge position that is facing Active, i can get it by launching object in direction of Active starting from Active(0,0) and storing the position of the object when it leaves the area, but i think there should be a better way "using math?!", what do you think?
    Untitled.jpg

  2. #2
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleSWF Export Module
    UltimateWalrus's Avatar
    Join Date
    Jul 2006
    Posts
    825
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the "using math" way of doing this would be to make a line segment for each side of your frame, then test if they intersect with the line coming from the player.

    if you are lazy or don't know how to do that, just set a very long invisible object to the player's position and orientation at all times. place detectors on the edge of your stage and see which one it overlaps.

  3. #3
    Clicker Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)

    Join Date
    Mar 2015
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for replying
    make a line segment for each side of your frame, then test if they intersect with the line coming from the player.
    Well, as a beginner i am afraid i do not understand this.
    I almost finished my first game, the thing is i wanted to learn all the possible solutions while progressing especially using math.

  4. #4
    Clicker Fusion 2.5 Developer

    Join Date
    Jul 2008
    Posts
    1,295
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Just off the top of my head (so possibly containing a few mistakes)...

    Formula for a straightline...
    y = (m * x) + c

    Calculate x and y components of line slope...
    mX = cos( anglePlayer )
    mY = 0 - sin( anglePlayer )

    Calculate slope...
    m = mY / mX

    NOTE: If the player is facing precisely up/down/left/right (0/90/180/270 degrees), these are special cases that you'd need to check for separately, as you'd get "divide by zero" errors otherwise (but the results should be obvious in these cases anyway).

    Rearrange original formula and substitute in a position we know is somewhere along the line (the player's position)...
    c = yPlayer - (m * xPlayer)

    X coordinate where the line leaves the top of the screen...
    xT = (screenTopY - c) / m

    X coordinate where the line leaves the bottom of the screen...
    xB = (screenBottomY - c) / m

    Y coordinate where the line leaves the left side of the screen...
    yL = (m * screenLeftX ) + c

    Y coordinate where the line leaves the right side of the screen...
    yR = (m * screenRightX ) + c

    If (xT < screenRightX ) and (xT > screenLeftX ) and (mY < 0)
    x = xT; y = screenTopY

    If (xB < screenRightX ) and (xB > screenLeftX ) and (mY > 0)
    x = xB; y = screenBottomY

    If (yL < screenBottomY) and (yL > screenTopY) and (mX < 0)
    x = screenLeftX; y = yL

    If (yR < screenBottomY) and (yR > screenTopY) and (mX > 0)
    x = screenRightX; y = yR

  5. #5
    Clicker Multimedia Fusion 2 DeveloperiOS Export ModuleSWF Export Module
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)
    King_Cool's Avatar
    Join Date
    Aug 2008
    Posts
    2,335
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Using 'Sinus'/ 'Cosinus' fuctions easily gets you this edge point without further adue ( No extra objects or doodads involved ).
    Sorry for not having time to explain further.

  6. #6
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export Module
    Fusion 2.5 (Steam)
    schrodinger's Avatar
    Join Date
    Nov 2014
    Posts
    3,155
    Mentioned
    27 Post(s)
    Tagged
    1 Thread(s)
    I'm also using slope intercepts all time,
    here are my quick notes on the matter, just in case:

    m coefficient= (Y'-Y) / (X'-X )
    or tan(angle of segment)

    b parameter= Y - (m * X )

    you need to calculate these only for the player actually,
    because as MuddyMole said, the edge lines equations are just
    y= 0/or Ybottom
    and
    x=0/or Xright

    then for the intersect point:

    x=(b'-b)/(m-m')

    or, if you have Y
    x= (y-b) / m

    y=m(x)+b

    Quote Originally Posted by MuddyMole
    NOTE: If the player is facing precisely up/down/left/right (0/90/180/270 degrees), these are special cases that you'd need to check for separately, as you'd get "divide by zero" errors otherwise (but the results should be obvious in these cases anyway).

  7. #7
    Clicker Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)

    Join Date
    Mar 2015
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello,
    Thanks guys these are interesting info, i already use sin / cos in my game to detect the nearest objects, tried to do the same thing with the screen edge but couldn't figure how to do it, i only have either x or y of the edge, hopefully your formulas will help me i will try them ASAP.

Similar Threads

  1. Detect if Angle is facing left or right
    By King_Cool in forum Multimedia Fusion 2 - Technical Support
    Replies: 5
    Last Post: 31st January 2013, 01:48 AM
  2. Object position relative to window edge?
    By ChrisBurrows in forum Multimedia Fusion 2 - Technical Support
    Replies: 1
    Last Post: 9th November 2011, 05:56 PM
  3. Getting position of active edge when scaled?
    By Clicktastic in forum Multimedia Fusion 2 - Technical Support
    Replies: 0
    Last Post: 13th September 2006, 01:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •