Midpoint Camera Distance Restriction

Welcome to our brand new Clickteam Community Hub! We hope you will enjoy using the new features, which we will be further expanding in the coming months.

A few features including Passport are unavailable initially whilst we monitor stability of the new platform, we hope to bring these online very soon. Small issues will crop up following the import from our old system, including some message formatting, translation accuracy and other things.

Thank you for your patience whilst we've worked on this and we look forward to more exciting community developments soon!

Clickteam.
  • Hi everyone!

    So I'm trying to make a special camera that positions itself at the midpoint between two points (the player and the mouse cursor). I used the midpoint formula to position the camera in the frame;

    Please login to see this attachment.

    Then I tested the frame and it works well, but the user can move his mouse super far away and see things way off the screen. I decided to add the distance formula to restrict how far away the camera can be from the player;

    Please login to see this attachment.

    However once the player reaches past the specified distance, the code stops working and the camera isn't positioned (as I expected). The question is, how can I keep the camera from moving past the set distance while still following the mouse and rotating around the player. Imagine a bubble around the player and the max distance would be the edges of the bubble. the mouse should still be able to move and rotate around the player at the fixed max distance. Here's the short few lines of code that I have so far. I assume I'll have to test if the distance is greater than 750 pixels, then add some code...

    Please login to see this attachment.

    Custom A* Pathfinding in MMF2: Please login to see this link.
    Random Tile World Generation: Please login to see this link.

  • I found this information online:

    In general, suppose that you are rotating about the origin clockwise through an angle θ. Then the point (s,t) ends up at (u,v) where
    u=scosθ+tsinθ and v=−ssinθ+tcosθ.

    I'm going to figure out the angle between using ATan2 and hopefully this should work.

    Custom A* Pathfinding in MMF2: Please login to see this link.
    Random Tile World Generation: Please login to see this link.

  • +Always
    ----Set Distance_Value to ( ODistance( "Player", xmouse, ymouse ) )
    ----Set Angle_Value to ( AdvDirection( "Advanced Direction Object", plr_x, plr_y, xmouse, ymouse ) )
    ----Set Camera_X_Value to ( Sin( Angle_Value )*Range(Distance_Value * 0.5, 0, 200 ) )
    ----Set Camera_Y_Value to ( Cos( Angle_Value )*Range(Distance_Value * 0.5, 0, 200 ) )
    ----Set Camera Position X to ( plr_x + Camera_X_Value )
    ----Set Camera Position Y to ( plr_y + Camera_Y_Value )

    I used the Advanced Direction Object for this.

    EDIT: For MMF2, use the Advanced Direction Object for getting the distance as well. I'm also not sure if there is a "range" expression in the special conditions object

    EDIT2: Yeah there is no range expression. you can either way check the distance, then check if it is above #, then set the distance to #
    EDIT3: MMF2 Version:

    +Always
    ----Set Distance_Value to ( Distance("Advanced Direction Object", plr_x, plr_y , xmouse, ymouse ) )
    ----Set Angle_Value to ( AdvDirection( "Advanced Direction Object", plr_x, plr_y, xmouse, ymouse ) )

    +IF Distance_Value > 120
    ----Set Distance_Value to ( 120 )

    +Always
    ----Set Camera_X_Value to ( Sin( Angle_Value )*(Distance_Value * 0.5) )
    ----Set Camera_Y_Value to ( Cos( Angle_Value )*(Distance_Value * 0.5) )
    ----Set Camera Position X to ( plr_x + Camera_X_Value )
    ----Set Camera Position Y to ( plr_y + Camera_Y_Value )

    - BartekB

    Join the Click Converse Discord! - Please login to see this link.

  • Thanks BartekB, it works now :) I've added my .mfa file in case anyone else would like to use it. I decided to use the traditional mathematical formulas for distance and angle calculations so I didn't have to include the Advanced Direction Object.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!