Announcement

Collapse
No announcement yet.

SetActorLocation weird issue when Simulate Physics Enabled

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

    SetActorLocation weird issue when Simulate Physics Enabled

    G,Day

    First up, is there a way to embed blueprintue into a post? https://blueprintue.com/blueprint/jdpkqel9/

    So what I am trying to achieve is this: Move an actor from one location to a location in front of my character, set by an Arrow Component, and either have physics enabled, or turn Simulate Physics on while the Actor falls to the ground.

    This is what I currently have, with Simulate Physics disabled and it works fine, except the Actor doesn't fall to the ground as Simulate Physics is disabled.
    Click image for larger version  Name:	ActorWeirdPhysics1.png Views:	4 Size:	99.7 KB ID:	1707414

    Now if I enable Simulate Physics on the actor, and then drop the item, it sets its Actor Transform to where I originally picked it up, like so:

    Click image for larger version  Name:	ActorWeirdPhysics2.png Views:	4 Size:	316.5 KB ID:	1707415

    I know it's something simple I'm missing, but I cannot figure it out. Just wondering if someone could point me in the right direction.

    Cheers,

    Note: Using 4.24.1
    Last edited by Aaron1178; 01-12-2020, 12:53 AM.

    #2
    What if you have physics off by default on the item and when you drop the item and then set simulate physics on it, does it work fine?

    Comment


      #3
      Sorry, I should have mentioned that I've tried that. I have also tried to enable Simulate Physics set a delay for 2 seconds, then disable Simulate Physics. Both of these have produced the same results.

      Comment


        #4
        I still cannot find a solution

        Comment


          #5
          I think what you are experiencing might be due to having two competing movement techniques going on.

          If you are moving an actor kinematically by setting its transforms directly, then its components, like your static mesh cube, which are children of the actor, will move along nicely with it. As soon as you enable physics on that component though it is effectively detaching itself from the control of the actor's transform and is then reacting to gravity and other physics forces.

          There are a number of ways you could approach the problem. You could leave the component with physics turned on and use a physics constraint between it and your character to move it around. The physics constraint could be on your character or the cube, whichever makes the most sense, or perhaps try using a physics handle in much the same way. You could also periodically poll the component's transform when physics is turned on and set the actor's transform to the same, so that when you need to disable physics again in order to move the actor kinematically the component and actor's transforms will line up and everything should be in the right place.

          Hope that helps.

          Cheers.

          Comment


            #6
            Thanks for the advice Ramasurinen, that information came in handy.

            So what stuck to mind was
            Originally posted by Ramasurinen View Post
            If you are moving an actor kinematically by setting its transforms directly, then its components, like your static mesh cube, which are children of the actor, will move along nicely with it. As soon as you enable physics on that component though it is effectively detaching itself from the control of the actor's transform and is then reacting to gravity and other physics forces.
            So I ended up working around this issue by the following: Updating the static mesh world transform, since essentially it's 'detached' itself from my actors transform
            Click image for larger version

Name:	ActorWeirdPhysicsWorkaround.png
Views:	40
Size:	60.4 KB
ID:	1708788

            Now it works as I intended it. Simulating physics when the Item has been dropped at its new location. Is this a viable work around?

            Comment


              #7
              I also attached my static mesh back onto my scene root after I completed my Simulate Physics(True) -> Delay -> Simulate Physics(False) operation, which helped when dropping an item from when it is attached to a socket.

              Comment


                #8
                Well, if a workaround works, it's viable! Good stuff. I would still recommend taking a look at physics constraint components though. They're extremely useful for this kind of thing. If you want to have actors carry other actors around, but still give them a bit of "life" by having them sway around a bit from physics and accelerations etc, instead of rigid transforms, they work great. Depends on what you need.

                Also instead of having your mesh component attached to a scene root, you can simplify your hierarchy by having the mesh actually be the root. Sometimes that can save you some hassle when figuring out collisions and transform issues etc.

                Cheers.

                Comment


                  #9
                  Okay, so I gave physics constraint components a go, and I can get them working outside of my character, for instance, I created a newton cradle with an anchor, a cable and a ball and it works. The problem I am having now is with setting it up. i cannot find any decent tutorials for this.

                  There are two attempts I have tried, all failing:
                  1. Create a Physics Constraint Component in my character components list
                  2. In my item blueprint, when the Equip(interface) event fires, I call SetConstraintedComponents feeding in the players skeletal mesh, and hand_l(default mannequin) and then a static mesh cubes as component 2
                  Tried Solution 2
                  1. Create Physics Constraint Component in my character components list
                  2. In my item blueprint, when the Equip(interface) event fires, I call SetConstraintedComponents feeding in the players skeletal mesh, and hand_l(default mannequin) and then a static mesh cubes as component 2
                  3. Attach to players skeletal mesh socket via AttachToComponent with correct socket information
                  I also found this https://wiki.unrealengine.com/Pick_U...bject_Tutorial on creating physics handles, but no good. I know the problem. The problem is setting it up and lack of experience. I do a ton of google searches on problems I am stuck on, and I only leave the forums for extreme cases haha.

                  Cheers

                  Also, I am wondering if someone could shed some light on how they approach these situations. So for example, I have a sword with simulate physics on, because I want the player to be able to push it around on the ground. Now the logical solution to me, would be to AttachToComponent, to say a socket on the left hand. But then it comes down to my issues. Instead of AttachToComponent, do I use Physics Handles or Physics Constraint Components?

                  Comment


                    #10
                    The best way I've found to set up the constraint (looking back over my own code, which I haven't touched in quite awhile) was to put the constraint component on the item that's being picked up, and then when calling set constrained components from within that blueprint, I have the static mesh component of the object being picked up as component 1, and the collision capsule of the character doing the picking up as component 2. I've found that function to be a little counter intuitive. As I've been using it, component 1 is the child (being picked up) and component 2 is the parent. As you've mentioned in your process, an interface is a good fast way to pass the reference to the character into the pickup item.

                    You're right though, there's not a lot out there in the tutorial department on this, and it's a bit tricky to get working. Once it does though it's pretty great. Just have to keep messing around with it a bit. Once you get a nice setup that works its easy to reuse on other objects.

                    For your sword idea, I think attach to component would probably be best, since it's a rigid item. If you're dealing with soft bodies I think a physics constraint would be better.

                    Good luck.
                    Last edited by Ramasurinen; 01-15-2020, 09:27 PM.

                    Comment


                      #11
                      Thanks again Ramasurinen

                      So I am understanding things a little better(I hope). So with rigid bodies like Swords, Guns and say Shields, because they are Rigid Bodies, I would attach them to sockets, as apposed to something like a backpack on the player, I'd set that up with Physics Constraints because it's not a Rigid Body and it should simulate physics to move around.

                      How would clothing work? Say you have long pants, obviously it would be a soft body, so would I constrain it with a physics constraint? I am trying to do this from an inventory, so how would I transform the clothing to the desired location? Do I attach the component to a socket, then set the constrained items?

                      Comment


                        #12
                        No prob. Yup, that sounds about right. A sword being bound to a socket on the character's hand makes the most sense, and you'd want a backpack to have a bit of flex against the movement of the character, so a physics constraint might be better for that. I'm not sure if you can set up multiple constraints for a single object, like the 4 straps of a backpack. Prob worth exploring!

                        As for clothing I can't really help you, sorry. Unreal has built in cloth simulation, so I'd recommend looking into that, but I haven't needed to mess with it yet for my game, so I haven't checked it out at all. Hopefully someone else can give you a hand there.

                        Good luck!
                        Last edited by Ramasurinen; 01-16-2020, 12:30 AM.

                        Comment

                        Working...
                        X