Announcement

Collapse
No announcement yet.

How to scale actor, continuously, based on the distance from the camera ?

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

    How to scale actor, continuously, based on the distance from the camera ?

    Here is a setup I got going:

    Click image for larger version

Name:	ur4_actor_scaling.png
Views:	1
Size:	14.4 KB
ID:	1187146

    Currently I spawn an actor at the end of the trace (when it hits "floor"). Actor is pretty big (scale 1) as when it's at the max distance it appears of a good visible size. However, when it's near the camera it looks too big. 10% of the original scale should make it look nice when near the cam.

    The idea is to scale actor based on the distance from the camera (which is already easy to get). When actor is between red vertical bars (see sketch above; along blue double ended arrow) it should be scaled from .1 to 1 based on the distance. Once it goes closed to the cam or farther from the cam (passed red vertical bars on the sketch, along red arrows), scale should remain constant (using last value).

    How do I do that (changing scale value withing the bounds and keeping it as it passes set thresholds in both directions) ?

    Thanks

    #2
    OnTick have a raycast between your target and your character camera component.

    Get the length of the raycast and feed it to a variable named currentDistance.
    When currentDistance is longer than startScaleDistance, don't scale the actor.
    When currentDistance is smaller than startScaleDistance, start scaling the actor.

    Still OnTick if scaling is on, set world scale of your actor to currentDistance / startScaleDistance.
    [Released] Multiplayer Combat Editor
    A-RPG Sacred Swords
    Auto-Chess Live Development
    Youtube Tutorials

    Comment


      #3
      Originally posted by Yun-Kun View Post
      OnTick have a raycast between your target and your character camera component.

      Get the length of the raycast and feed it to a variable named currentDistance.
      When currentDistance is longer than startScaleDistance, don't scale the actor.
      When currentDistance is smaller than startScaleDistance, start scaling the actor.

      Still OnTick if scaling is on, set world scale of your actor to currentDistance / startScaleDistance.
      It works, but not quite :/

      Basically at startScaleDistance scale is x1 and by the time it gets to farthest distance scale is like x13. I need to have scale x1 at starting point and scale of x2.5 (or whatever I define, depending on field test results, so to speak).

      Comment


        #4
        I am guessing I should either stop scaling after certain distance (when currentDistance / startScaleDistance == 2.5) or clamp currentDistance / startScaleDistance between 1 and 2.5

        Comment


          #5
          Ye

          Or do something like

          Max dist - min dist = difference dist

          Max scale - min scale = difference scale

          Current scale = min scale + (current dist / max dist * difference scale)
          [Released] Multiplayer Combat Editor
          A-RPG Sacred Swords
          Auto-Chess Live Development
          Youtube Tutorials

          Comment


            #6
            Originally posted by motorsep View Post
            I am guessing I should either stop scaling after certain distance (when currentDistance / startScaleDistance == 2.5) or clamp currentDistance / startScaleDistance between 1 and 2.5
            Hey motorsep,

            Try using normalize to range, with the min value as your closest point and the max value as the furthest distance. This should allow you to scale in a 0-1 range within the distance you've set.
            Adam Davis | Marketplace Support | Epic Games
            How to report a bug? | Installation & Setup issues? | Answerhub Bug Reports | Twitter

            Comment


              #7
              Originally posted by Adam Davis View Post
              Hey motorsep,

              Try using normalize to range, with the min value as your closest point and the max value as the furthest distance. This should allow you to scale in a 0-1 range within the distance you've set.
              Hi Adam,

              Currently I feed value of currentDistance / startScaleDistance into Make Vector and then into Set Relative Actor Scale node. If I normalize the value, then when 0 is fed into Actor scaling node, it will see no actor (perhaps I am not fully understanding how normalize to range works).

              Comment


                #8
                Here is what I've set up. Keep in mind, you'll have to modify it to fit your needs, but this seems to work on my end:



                effectively what is occurring is that I have a sphere collision component that, when overlapped, sets the tick to enabled so the actor only ticks when the player is within the collision sphere. On tick, it gets the length of the vector between the cube mesh and the player, then sets that into normalize. What normalize does is it takes a value and checks where it is between two fixed points, min and max. In this case, it checks to see if the length is somewhere between 0 and 1000, or the full diameter of the circle. That value is then turned into a float between the two values, or, another way to view it would be the percentage between 0 and 1000. So 750 would be .75, etc. Because I wanted the object to grow, not shrink, as I approached, I then subtract 1 from the value, so 1000 will be 0 and 0 will be at -1.0. Get the absolute value of this and you should be able to plug that directly into your scale.
                Attached Files
                Adam Davis | Marketplace Support | Epic Games
                How to report a bug? | Installation & Setup issues? | Answerhub Bug Reports | Twitter

                Comment


                  #9
                  [MENTION=49]Adam Davis[/MENTION]

                  I tried fitting your setup into my BP, but ended up simply adding clamp to node Worked wonders.

                  P.S. Actually I still need to figure out your way. With my simple clamping actor might stop scaling up half way through, so it's not quite correct. Will dig it.
                  Last edited by motorsep; 08-04-2016, 03:28 PM.

                  Comment


                    #10
                    [MENTION=49]Adam Davis[/MENTION]

                    Tried messing with Normalize to Range node:

                    http://i.imgur.com/n6NLRxo.png

                    Here is the print out I get:



                    So, basically it scales from 1.000 to 1.005, where I need to scale up from 1 to 2.5 (or from 1 to any higher value I determine usable, 1 to 4.2 for example), where at 0 length scale is 1 and at 1500 length scale is 2.5. What am I missing ?

                    Thanks

                    Comment


                      #11
                      Originally posted by motorsep View Post
                      @Adam Davis

                      Tried messing with Normalize to Range node:

                      http://i.imgur.com/n6NLRxo.png

                      Here is the print out I get:



                      So, basically it scales from 1.000 to 1.005, where I need to scale up from 1 to 2.5 (or from 1 to any higher value I determine usable, 1 to 4.2 for example), where at 0 length scale is 1 and at 1500 length scale is 2.5. What am I missing ?

                      Thanks
                      The normalize to range node is used to take values and put them to a 0-1 scale, the 1.005 may be a float point error. If you need something from 1-2.5, you will have to use the clamp as described above.
                      Adam Davis | Marketplace Support | Epic Games
                      How to report a bug? | Installation & Setup issues? | Answerhub Bug Reports | Twitter

                      Comment


                        #12
                        Alright, solved!

                        Basically I feed distance delta into Normalize To Range node, then feed the output into Lerp node's Alpha with min/max set to whatever min/max scale I need to set actor to and lastly I feed Lerp's output into Set Actor Relative Scale 3D node. Works like a charm

                        Comment

                        Working...
                        X