My aim is to move a mesh from point A to B. So far, I’ve been doing it using a Timeline
node in combination with a Set Relative Location
. This works fine but is there any better way to do this?
In particular, I want to deal with collisions too. For example, when the path is obstructed, it stops. With the method I’m currently using, it ignores all solid geometry and goes through them.
Also, I want to have more control over the speed of the displacement. How can I use a value in combination with the Timeline
node to control the speed?
I’m very interested to hear your ideas.
You can use the following four nodes to move actors to a location or actor.
If you want to move the actor directly in a straight line to certain location, use the last node Set Actor Location
and make sure to check Sweep
which will do collision checks and will prevent the actor from overlapping with other collidable objects.
The first three use pathfinding and may result in the actor not following a straight line path.
To control the speed you need to multiply the velocity with the Delta
and use that to drive location updates. You could also use the Lerp node in conjunction with a Curve to have non-linear velocity - like ease-in ease-out etc …
Add movement input? If your actor is a pawn I think you can use it, but then performance would be a problem.
But it would detect colliisions, but you can also detect collisions on the tick function, if is overlapping stop moving translating.
As mindfane says, if you check sweep param on set actor location it does something with the collision.
There is no correct way to do it in my opinion, just ways that they take more performance or less, or the code can be messy or not…
You can Set Rate of the Timeline:
If you want to move the actor directly in a straight line to certain location, use the last node
Set Actor Location
and make sure to checkSweep
which will do collision checks and will prevent the actor from overlapping with other collidable objects.
One note regarding this, if you attempt something along the lines of:
Sweep will not work - note the component hierarchy, Sweep only cares about the root and currently the root has no collision.
If you wish to move just a component(s) of an actor, rather than the entire actor itself, this will work fine, though:
Another method not mentioned above:
- the
InterpToMovement
component
While its data can be updated dynamically, it’s more of a fire & forget thing that is an inflexible pig to work with.
Thank you for the detailed answers. I played around a bit with sweep and it works. But I realized that I want some more control over what happens on collision.
I tried using On Component Hit
and On Component Begin Overlap
but that is not really a viable option. I guess I could parent an invisible box to the moving object (the door) and use that to check for collision. But I really hope a better way exists. This is unnecessarily too process intensive.
Also maybe a better approach is to use physics based movement. Is it a good idea to use physics based controls for an object like a door?
I’d say no; unless you actually want physically simulated door that swings naturally, or can be interacted with in a physical way / with forces or impulses. The answer depends on how you want the door to behave.
I tried using
On Component Hit
andOn Component Begin Overlap
but that is not really a viable option.
Why not? This works and specifically accounts for sweeps:
You may have a reasons, ofc. Just asking why you think it’s not viable.
I guess I could parent an invisible box to the moving object (the door) and use that to check for collision. But I really hope a better way exists. This is unnecessarily too process intensive.
It’s a pretty common solution in certain scenarios. That’s precisely what colliders are for. Begin / End overlap are sweep independent, too. Perhaps you have a Nicely Detailed Mesh for a Big Spiky Trap, but only the spikes are deadly, the rest of the trap is safe to fiddle with. As a bonus this event will trigger once rather than spam every frame like the DoOnce-gated Hit event above…
One note:
- rotations & Sweep is a no-no. Maybe in UE5… @mindfane ?
Yeah I see. I was doing it wrong. Still Sweep is a bit finicky… I need to play a bit more with it to get the grasps of it.
Thank you for your detailed response!
I did play around with sweeps and moving objects with Add Force
but I don’t feel like either of them is a good system to build upon.
I want to setup a door opening system and I want to mix a bit of physics based movement and sweeps.
Here is my situation:
A rigidbody box is obstructing the path of the door. What I want to happen is the door push the box to the other wall (so that it can’t be pushed any more) and then stop. As if the door is crushing the box against the wall.
I can’t embed 2 pictures in post. Continued…
Like this:
I haven’t been able to get this setup working in Unreal so far. Sweep immediately stops when hits an object even a rigidbody. Basically I want to replicate how doors work in real-life… using physics (or at least give the illusion of it).
Like this maybe, may need TWEAKING
The obstacles are simulating physics.
There’s a lot of things that could make it better, ofc. Like ensuring that only the tip applies the force. Currently it will fling anything that touches the whole thing.
And you can isolate what is being Swept against with collision channels:
This particular door interacts with Physics Body object type only and will ignore everything else.
Also, this may not even be the best way about it. Depends on how whimsical this is allowed to be.
Yeah I’m new to Unreal. I’m getting to know the engine more and more, and how can I get the things that I want done.
Yeah that is true and I agree that it should be done that way too.
Yeah that an interesting way of doing it. Thanks. I’ll play with it and tweak it a bit and I’ll report back how it looks.
Just couple of days ago, I found a pretty good solution that could even be improved even more. I’ll post a video of a working example along with the blueprints here very soon.
While discovering this method, I got a bit disappointed with the physics system implemented in unreal engine 4. I’ll elaborate on this when I’ll post the method.
Before delving into the blueprint, here is a basic demonstration of it:
The box is being physically pushed around by the door.
The same setup with the box out of way:
This is using the Move Component To
node to move the door. The move component node affects physics objects which is very nice.
So using this node alone, it will crush physics objects into walls and make the physics engine freak out and it launches them in a direction. I combined this with a Box Trace By Channel
node to detect when the distance between the door and an obstruction is less than a value, it stops the movement.
Then the exec node is connected to the
stop
input on Move Component To
. Here is the same demo with the trace-lines visible.
I think a better way to do it is is to use a Multi Box Trace By Channel
to detect the distance of the obstruction from both sides but that is besides the point here.
Currently in the video demo shown above, the door looks like it has an automatic stopping sensor and it does not look like the box is being crushed at all… but more importantly, look at this:
The door object just clips into the rigid-body box… this disappointed me a bit… I was expecting a much better physics implementation in UE4. But maybe I’m doing it totally wrong so please let me know your thoughts on it too.
I’m struggling to simulate a crushing effect… I was hoping I could use physics simulations as much as possible but unreal doesn’t seem to like it that much…
I like to hear other people’s thought on this matter and if anybody knows a viable method to achieve something like this.
Why not just use physics for the door? Did you ever take into account the mass of the objects in front of the door?
The door can also grab on to objects and keep them from being moved by the player:
And the player can ride it:
This. But OP specifically did not want to use physics for the door, hence my hackaround suggestion.
I did play around with sweeps and moving objects with
Add Force
but I don’t feel like either of them is a good system to build upon.
I want to setup a door opening system and I want to mix a bit of physics based movement and sweeps.
edit: but then:
I was hoping I could use physics simulations as much as possible but unreal doesn’t seem to like it that much…
So I’m confused a bit.
And now they have a fiddly system that may be too difficult to scale, and underperform. I don’t like the latent move for this, that’s going to be a nuisance in the long run.
And the player can ride it
Extra features!
Oh wow, I really over complicated the solution… I remember going with physics was my first option and I kept going back to it to make it work… but it always ended up wrong…
This seems to be a very good way of doing it.
Thank you much for the help and sorry for the confusion caused :PP