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.
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.
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.
Thanks for the advice Ramasurinen, that information came in handy.
So what stuck to mind was
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
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.
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.
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:
Create a Physics Constraint Component in my character components list
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
Create Physics Constraint Component in my character components list
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
Attach to players skeletal mesh socket via AttachToComponent with correct socket information
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?
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.
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?
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.