Announcement

Collapse
No announcement yet.

Center RTS Camera on Zoom Out

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

    Center RTS Camera on Zoom Out

    I'm trying to make a Top Down RTS camera i've made center the world(on X,Y not Z) depending on how much it is zoomed out and wondering about the best way to go about it? (Something like supreme commander)

    I'm quite new to Blueprint and programming in general so i've been thinking about a few ways to do it with as little programming as possible.

    First one was making a collision cube that scales as you zoom out so it always looks the same size to the camera,
    so that when you are zoomed out enough it will hit the map bounds and force the camera to nudge whatever direction it needs to not collide anymore.
    This came with a few problems to me so if put this away for now.

    Second thing i tried was making a pyramid shape out of collision boxes. Something like the fridge material below. Drawn by uh.. my friend
    Click image for larger version

Name:	pyramid_.png
Views:	1
Size:	6.8 KB
ID:	1215856
    This wont even collide for now because the camera zoom is setting a Spring arm length and not adding an offset so it's not sweeping. Even if it did it would only get stuck.

    Not afraid to try my hands at a programming approach as i think it will yield the best result anyway.
    I just need a little guidance so any help is appreciated.

    #2
    [MENTION=324271]Ziecore[/MENTION]:

    1. Bit of graph:

    2. Bit of graph:
    Main channel:
    https://www.youtube.com/channel/UCGC...o9s3YcA/videos

    Comment


      #3
      First of thanks for your reply.

      I'm looking at your blueprint now and i think i understand what is going on for the most part and i'm working on trying it out right now.
      However correct me if i'm wrong, but this method would only reset the camera to "origin" whilst im zooming out?
      If so it's not really what i need.
      I need to limit my movement when i am fully zoomed out to 0 and when im fully zoomed out it also needs the be in the center of the map.
      So for example when im zoomed in as far as i can, then i can move 100% of map until i hit my map bounds.
      But when i am zoomed out as far as i can, then i cant move at all, because this will be the "strategic view" in the center of the map.

      Update: I have now tried to implement your method as best as i can, but i must be missing something because when i zoom out it instantly snaps to minimum zoom amount and gets stuck there.

      Comment


        #4
        This seems like a similar problem.

        Coming next is my read to the problem, might be wrong with the math but I found the problem pretty intriguing

        You could define your pyramid with 4 points defining the four corners of your map and another point defining its center (the top). You might be able to find each plane's normal by using cross product. Once you have all the normals, you should be able to decide if you're inside the pyramid or not. With this result, you should stop increase in the Z axis. Depending on the plane you're getting out (the one with dot product < 0), you should stop the camera from moving towards it.

        Good luck!
        Last edited by MatheusRC; 04-03-2017, 05:54 PM.

        Comment


          #5
          Sorry for bringing this post up again and for not replying sooner. But rather than post a new thread with my updates i think its better to bring this one up since it about the same problem.

          I looked at the link you sent several times. I get the general idea but have no clue where i would begin to implement that into blueprint. But i'm sure it's much better than my solution:
          Click image for larger version

Name:	2017-05-14 22_03_38-Brimstone - Unreal Editor.png
Views:	1
Size:	139.2 KB
ID:	1128057
          Click image for larger version

Name:	2017-05-14 22_03_47-Brimstone - Unreal Editor.png
Views:	1
Size:	180.8 KB
ID:	1128058


          The sections are nearly identical as in the second image. This works quite well though i'm not sure about the order of execution especially with the sequence node you can see in the first image. There's probably a much better way to do it. But like i said it works.

          here you can see how i update the "Move Range" variable:
          Click image for larger version

Name:	2017-05-14 21_42_57-Brimstone - Unreal Editor.png
Views:	1
Size:	86.2 KB
ID:	1128055

          Not sure if this needs explaining as most people here are probably much better at blueprint than me.

          The "Origin X Dynamic" is just a cube at the end of my Spring Arm so obviously always at the center of the screen.

          Basically the more i zoom out the less i can move and it pushes me inwards to the center of the map.

          Possibly the biggest problem i have with this solution is that i'm using Lerp and if i increase my cameras movespeed it can basically "overpower" the lerp
          allowing me to move farther than i should be able to and as soon as i stop moving the function will push me back again depending on how strong the Lerp Alpha is ofcourse.
          Have also tried this with FInterp but there the problem is even greater.

          Hopefully there's something simple i can add or change in my function to fix this but i have no idea what or if anyone could help me working with Dot products i would apprecitate it
          Attached Files
          Last edited by Ziecore; 05-14-2017, 04:08 PM.

          Comment


            #6
            I'm happy you got it working!

            The screenshots are not very clear, but seems like you could separete your logic into functions.

            You might want to group look-a-like set of nodes into a function. Look what changes in each set of nodes and maybe add an input to your function.

            By doing that you'll probably make your logic easier to understand for yourself and for us. If you manage to do that, post these functions here we might even be able to see clearly each node .

            Btw, the Sequence will execute each pin in order, if you were wondering.
            Last edited by MatheusRC; 05-15-2017, 04:43 PM.

            Comment


              #7
              It's definitely not optimal. I've spent hours and hours just trying to think of ways to improve the logic but i'm not really sure i follow what you mean i should do?
              I'm quite(very) new with blueprint and programming in general, Spent about a month with it on and off.

              I'll try explaining it a bit further:

              The first and largest image shows basically the entire function for the "pyramid bounds".



              Every section of it is almost identical to the second image IE X+ X- etc.



              Origin X/Y is the coordinates for the center of the camera view at ground level.
              In the last picture where i set the "Move Range" you can see that when i am fully zoomed in the Move Range will be at it's maximum value which is the entire size of the map
              and when it's fully zoomed out it will be 0 meaning i can't move at all, Which is exactly as i want it ofcourse.



              Again in the second image you can see the logic for pushing the Origin/Center of the camera back to within the bounds and i do this for X and Y + both - and X+Y+ etc for the four corners.
              So that no matter where i try to go it will always be pushed back correctly.

              Which brings me to the real issue with this.
              I'm using Lerp to make sure it's within the bounds the "- 1"(In the second image) is just to make sure i don't get stuck anywhere since i cant move if im outside of the bounds.
              Neither Lerp or FInterp are ideal for this since i have a Move Speed for the camera and if i increase it i can potentially overpower the Lerp/FInterp and force it outside of the bounds.
              Initially i tried to make sure i cant move the camera if it's close enough to the move range in any axis but this only resulted in it being push back and imediatly trying to go outside again and since it's ticking it just looks extremely choppy.

              So i'm really looking for a way i can have it be more rigid. When it's at the limit where it shoulnt be able to move any more then it should just stop. Perhaps this is just overly complicated and it'd be easier if i learned about using Dot Product as in the link you sent?

              I would need major help with doing that i think

              Edit: Added the same images again so it's easier to follow.
              Edit2: Sorry my forum posts are probably more of a disaster than my functions.
              Edit3: Regarding the Sequence i do know what it does, more of a question if it should be there at all. Since i cant be at X+ and X- at the same time it doesn't really seem to be a big deal but there's most likely a better way of doing it.
              Last edited by Ziecore; 05-15-2017, 06:22 PM.

              Comment


                #8
                Just some thoughts: instead of handling the X and Y at the same time, couldn't you first adjust the X then adjust the Y? I mean, If I follow correctly you could check if X and Y is inside the range (-MoveRange,+MoveRange).

                Do you mind showing what's inside the Collapsed Graph? (...SetWorldLocation)

                Comment


                  #9
                  I do that at the end of the graph in the first picture where you see the sections after the Sequence it checks and adjusts X+- and then Y+-.
                  To make it clear the first four sections named X+Y+ and so on are for the four corners of the map and the ones after the sequence are for the four sides.
                  The problem having only those four sides is that it will allow me to go into the corners of the map and as soon as i try to move any other direction it will snap me back in to the center of the map.
                  I dont fully understand why though.

                  As for the Collapsed graph i'm sorry, that does seem confusing having that collapsed graph, but it's just that, it's a regular ol' SetWorldLocation nothing else.
                  Only reason i collapsed it was because i didn't want to see the output from them making them a bit more compact.

                  Coming this far feels great, had to do a lot of thinking making this seems so silly that i'm completely stuck trying to make such a simple change to it.
                  I hope you understand what it is i am trying to change with it? Not sure if it all seems very confusing or not.
                  Last edited by Ziecore; 05-16-2017, 09:50 PM.

                  Comment

                  Working...
                  X