Problem with constantly updating actor location and having it move smoothly

Hello

I have a problem with making an actor move smoothly. I seem to have tried every possible solution, but nothing solves the problem for me.

What I want to achieve:

  1. Player picks up an object
  2. Object starts updating its position to always be at the position where the owning player is looking at (and moving at)
  3. The updating of the position happens smoothly

What is not working:
The updating of the positions does not happen smoothly, there is snapping as the object position is updated from A to B

What I currently have:

  1. Timeline replacing Event tick - constantly looping
  2. Timeline for lerping from the old position to the new position - I realize I am not using the timeline correctly by using the “Set New Time” with the 0.2 value, but this is the best solution I have actually gotten to work. Problem with this is that the speed is too slow and if the character runs fast the object does not catch up. If I up the value to 0.3 or higher it starts becoming not smooth again.

I believe the outer TickTimer is constantly overriding the MoveTimeline, I have tried having some branches there to check if the MoveTimeline is finished before calling it again, but this just means there is a weird gap where the object stops moving for a moment after the MoveTimeline finishes and is started again with the new locations.

If anyone could point me to the correct direction here that would be great.

Did you tried magic of interpto? The Subtle Magic of InterpTo() - Unreal Engine

You could constantly vector interpto to some target, then just change target to new one.

Ps.
I just had idea (but that is kind of hack, and i am not sure if it will work at all).
You (probably) could use camera arm, ie put your object on end of camera arm. then menipulate arm rotation and distance (a bit of vector math).
Then enable lagg for camera arm. And it will nicely interpolate between locations.

I worked exactly on something like you and solved it :slight_smile: and it was suprisingly easy…
I just got location of actor and following actor, used node get unit direction vector and this value i added to movement of actor who following. Movement is “smoothly replicated” by engine default so im using this kind of smooth movement/following

edit: i done it this way because i have multiplayer game… in single player imo interpolation can work… for good results you must modify some numbers in movement component, i dont remember which ones

Thank you and Name368

First of all I tried the VInterpTo, but it is still not smooth. It seems like the tick is interrupting the interpolation and reseting the position constantly.

The spring arm suggestion is very nice. I hacked something together really quickly and the object does indeed move totally smoothly when it is attached to the spring arm and I do not even have to do the updates manually in the tick event.

Name368 - I also have a multiplayer game. If my object that I want to move is basically a simple static mesh actor without a movement component, I can’t really add the movement input right? Should I work around that somehow?

That was me with my other account…

Of course there are still problems with every solution. How is this so complicated. When I attach the object to the springarm it moves nice and smooth, but there is no collision on attached actors as I have found out as they do not perform a sweep, so the object that is carried can just be clipped through objects and the player can just release the object inside a wall or something like that. Working around it seems way more complicated than it should be.

So I am not sure which solution I should be trying to get working here. Seems like I have to keep working on just manually updating the location of the actor that is carried, but VInterp is not smooth for me. Still seems like the Tick event is interrupting the Vinterp by constantly updating the old location (which is slightly different on every frame) causing the object to jitter.

You can turn on camera collision for arm. Not sure if that will work for other objects than camera. Camera collision i think is one of arm settings.

I think I have it correctly set up. In the demos for spring arm, the camera does in the end just clip through walls if there is nowhere for it to fit.

image of collision settings on spring arm:

Also, I am not simulating physics on the object that I pick up, because physics objects don’t replicate very smoothly over the network and I don’t need physics to be enabled when objects are carried.
If I enable physics on the objects they do collide with the world slightly (when attached to the spring arm), but it is very easy to make them unstable and put them inside other actors (this is not a problem with the solution that constantly updates the locations as I have on my original post)

EDIT:
This seems like the problem I have with attaching the object to my character:

Bumping. Anyone? At this point I would be happy if someone told me what the correct way to approach this problem would be. I bet this has been done a thousand times in UE games, I wonder how? Updating the location in event tick seems like the closest I have gotten to what I need (collision enabled on carried object), but it is not smooth…

I would suggest checking out this tutorial. Should do everything you are looking for and it worked perfectly for me.

Have you tried simply attatching the object to the character actor? There’s an attach actor to actor node (or something similarly named)

Did that work for you in a multiplayer context? As I have understood replicating moving physics objects won’t happen smoothly. I Will try it out again though. Thanks

Yes, as I mentioned above, if I attach the object to the character the movement is smooth, but there is no collision on the object allowing the character to place it inside walls and such.

Odd. Thisll sound stupid but have you tried adding a colision sphere (at least while the object is attached?

What is the object in question? Is it a mount, is it some kind of weapon? So you missing the Component Collision Sphere?

You can have collision on a camera on a swing arm, so it won’t clip, for sure.

If you don’t want it called every tick, call the update function on a timer loop. With Interp, you do want to restart it with the current position each time. If it’s jerky, there is someone wrong with the starting position being handed to it, adjusting the time, ease in and out may help solve it, or there is a logic error.

Your approach with timelines is unlikely to work, if you want a reasonably physically-based behavior.

You have to consider how fast you want the object to respond when the player turns. If the player does a wrist-whip 180, is the object there right away?

The most robust way to provide “smooth, physically accurate” movement is to use physics simulation.

  • turn on physics simulation for the object
  • give the object a sphere collider
  • turn off gravity for the object (optional but often helpful)

Now, each tick, the object should run logic something like:

  1. Determine where it should be (player + player-look-vector + some offset, offset by whether it’s colliding)
  2. Determine where it will be 0.1 seconds from now (position + velocity * 0.1)
  3. If the difference is greater than some maximum tolerance, “snap” the object to the desired location, without checking collision
  4. Else apply a “thrusting” force at the center of the object that is ThrustConstant * (should_be - will_be)
  5. Calculate what orientation the object should have, based on the vector from object to player, and make it have that orientation
    (or, alternatively, run a second desired/actual delta that applies torque to the object to make it spin.)
  6. Apply damping to linear and angular velocities. (multiply by (1.0 - 0.1 * dt) or whatever)

The values of “0.1 seconds” and “ThrustConstant” and “maximum tolerance” are tunable variables in this system.

What you have implemented above is known as a “PD” controller (proportional-derivative) for position.

You can then read up on other ways of tuning this controller, including adding an “I” term (PID controllers, the staple of motion control,) and using differential equations to get the “exact” values to apply when you want the object to “brake perfectly” to get to the position in question with the minimal time possible given a specific available impulse.

If instead you want a “user interface” type behavior, why not just glue the object to the position it needs to be? Calculate the desired position each frame, set the object to that position each frame, done!

Bumping, anyone ever find a solution?