Announcement

Collapse
No announcement yet.

Clamp Player Movement within Screen View / Screen Edge

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Clamp Player Movement within Screen View / Screen Edge

    Hi,
    I'm working on a topdown space shooter game for the mobile device and I need a way
    to stop the player ship from moving off the screen.


    Click image for larger version

Name:	screenEdges.JPG
Views:	1
Size:	107.7 KB
ID:	1200648


    In the Playership actor(pawn blueprint), "SetActorLocation" is used to move the player location and after that
    I use this clamp function to limit the movement, but how do I get it work at the screen edge.

    This is what I have so far.
    At the moment those are just fixed values (-100,100) for the min and max clamp values, but I'm kinda stuck
    on figuring out how to get those clamp values from or depending on the screen size


    Click image for larger version

Name:	func_ClampBp.jpg
Views:	1
Size:	341.2 KB
ID:	1200647


    I have tried several ways like getting the screen size (X & Y)and divide those by half and use it for the
    min and max clamp values, but no luck
    I have failed trying to get this to work since this week !!










    .

    #2
    Originally posted by IvanRichard View Post
    Hi,
    I'm working on a topdown space shooter game for the mobile device and I need a way
    to stop the player ship from moving off the screen.


    [ATTACH=CONFIG]118087[/ATTACH]


    In the Playership actor(pawn blueprint), "SetActorLocation" is used to move the player location and after that
    I use this clamp function to limit the movement, but how do I get it work at the screen edge.

    This is what I have so far.
    At the moment those are just fixed values (-100,100) for the min and max clamp values, but I'm kinda stuck
    on figuring out how to get those clamp values from or depending on the screen size


    [ATTACH=CONFIG]118086[/ATTACH]


    I have tried several ways like getting the screen size (X & Y)and divide those by half and use it for the
    min and max clamp values, but no luck
    I have failed trying to get this to work since this week !!

    .
    You can put collision boxes around map which block only your movement... or you cant use this for your project?

    Comment


      #3
      I can't use collision boxes. It has to be based on the screen edges since the screen size would be varying for different devices.
      Last edited by IvanRichard; 11-18-2016, 11:58 PM.

      Comment


        #4
        "Project World to Screen" coupd help.. Never tested it either..
        My idea would be to Project the Position of the Player to screen coordinates, and ask if the player is outside screen width/height..

        Comment


          #5
          Originally posted by Chaosgod_Espér View Post
          "Project World to Screen" coupd help.. Never tested it either..
          My idea would be to Project the Position of the Player to screen coordinates, and ask if the player is outside screen width/height..
          Hey thanks Chaosgod_Espér, that kinda actually worked, can use it to detect the player at the screen edges
          I setup it up this way

          Click image for larger version

Name:	PlayerNearScreenEdgeDetect.jpg
Views:	1
Size:	364.4 KB
ID:	1118624

          .
          Now I need is to stop the movement or set the player position to the previous location. Any way to do it ??




          .
          Last edited by IvanRichard; 11-19-2016, 05:42 AM.

          Comment


            #6
            any way to bump back the player to the previous location within the screen edge?

            Comment


              #7
              Originally posted by IvanRichard View Post
              Hey thanks Chaosgod_Espér, that kinda actually worked, can use it to detect the player at the screen edges
              I setup it up this way

              [ATTACH=CONFIG]118151[/ATTACH]

              .
              Now I need is to stop the movement or set the player position to the previous location. Any way to do it ??




              .
              Ill try this, but can u tell me on which wire is plugged your first sequence ?

              Comment


                #8
                Thank a lot, now I'm looking to make my character move with the screen edges when he's on the end cause the camera is scrolling from left to right

                Comment


                  #9
                  Its a custom function that is connected from the tick event.
                  Last edited by IvanRichard; 11-24-2016, 02:06 PM.

                  Comment


                    #10
                    Originally posted by IvanRichard View Post
                    Its a custom function that is connected from the tick event.
                    Thank you, did you find how to to stop movement when the character reach the border ?

                    Comment


                      #11
                      Even tho this is 2 years old, Nobila would need to set the velocity of the movement in that particular direction to zero (for those scoping for answers), cheers!

                      Comment

                      Working...
                      X