Set physics actor velocity same as pawn

Hi all, I am trying to apply exactly the same velocity of my character to an actor. I retrieve the movement component of the character and get the velocity from there, and then apply the velocity to the actor using Set All Physics Linear Velocity every frame. I understand that this node is not recommended for physics simulated objects, and I notice that the actor is slightly slower than the character, so I wonder if anyone knows a better way to do this?

Hmm, I don’t have much experience in this field. But have you made sure both the mesh and character are using the same physics values like mass? The character component has a property to delay the movement of a character. These could well factor into the reason you may get different results.

I tried setting both the masses the same, but unfortunately the results are still the same. Please let me know what property you are talking about. Right now, the pawn is actually faster than the actor when pulling or pushing.

I’m not using attach to component or physics constraints because both solutions come with collision issues (the first removes collision from the actor entirely, the second only affects other physics actors).

Hmm, I hope someone else can help us out then! I will probably need something similar in the near future as well!

1 Like

Hey @DigitalGreenTea!

What is it, functionality wise, that you’re trying to do? I’m trying to see if a cable might be useful here. :slight_smile:

If you are doing this on the tick of the actor, it would always be a frame behind, right? Maybe you try doing it from the tick of the character.

I’ve attached a video showing what I’m trying to achieve. Basically, I want my character to be able to pull or push objects. The box can be pulled in only four directions, and the sphere in all directions. The logic for that is set up correctly, I’d say, but the velocity when moving is off and not one-to-one what I’m trying to design.

The following issues persist:

  • the pawn is faster than the actor, so it could be that the current velocity vector from the movement component isn’t exact. At some point when pulling, the pawn looses the connection to the actor.
  • due to the pawn being faster, a collision happens when pushing, the movement is no longer smooth (although I think I should disable pawn and this actor’s collision when in push/pull state to avoid this issue)

Good thinking! I just moved the logic to the tick of the character, but unfortunately the velocity results are the same.

Are you using a button to push?

If you are, consider attaching the block to the character until the button is released! You can use the AttachToActor node and I THINK the settings are “Keep Relative” so when the character moves back and forth it stays the exact distance from the character. For the sphere I’d leave the Rotation unlocked if you can.

Maybe take a different approach.

Rather than match velocities like this, scale the force you apply to the other actor based on the velocity delta between it and the character. This would make it slowly catch up, and then lag if it is too fast.

Sorry I just now looked at your video. Seeing what you want to do I would just set the location every frame (event tick). You just need to duplicated it being snapped together. I thought maybe you were simulating a drone following you or something.

Just want to thank you for considering to help me out! Attaching the actor to the pawn is what I did initially, but unfortunately the approach comes with issues:

  • the collision of the actor is removed, as the parent (pawn) collision dominates. I could stick the block into a wall.
  • because it’s not a physics simulation, if I were to move the block off a ledge, it would stay in the air rather than fall down, which just would defy player expectations.

I also tried using a physics constraint while attaching, and it has almost all the issues as above, but the interactions with other physics actors work.

Honestly this would be just super easy if I could just get the correct velocity of the pawn and apply it to the block… :sweat_smile:

I think this could be the way to go. If I simulate physics while setting the actor location (teleporting), and if I still hit something while teleporting it affects other actors or a wall blocks the actor. This fixes issues I have been having. But how can I do the exact calculation so that it’s it always in front of my character and how would I handle slopes?

Although I must say, that simply duplicating the pawn’s velocity onto the actor is the easiest, and most convenient and smooth solution. I just don’t understand why the character velocity doesn’t match the one of the actor (the cube). Is this an engine bug?

Sorry I was away from the forum for a while and wasn’t getting thread notifications for some reason.

So it sounds like you want this to behave as though you are dragging a semi-sticky object, right? Like a magnet dragging a larger piece of metal? If you bump into something do you want to become “dropped”? Like how would you handle sliding around a corner and not allowing room for the thing you are pulling? Give me an idea of how you would want that to work.

If it turns out you only need an answer to this question and don’t want to bother with a different solution let me know. I can help you there as well.

Looking at your example again, I think I see why this is happening.

There is likely physics friction between the floor and what you are holding, but not the pawn. So even though you are setting the velocity to the same, physics is making the dragged object move a little slower.

The best way to solve this is to apply force to the pulled object based on how far it is from where you want it to be (i.e. less force when close to target point, more when farther). This way it might jitter slightly, but the jitter will feel organic and smooth.

I do almost exactly what you are trying to do in my project and would be happy to share my code approach with you if you like. Let me post a little video here of what I do so you can see if it matches what you are trying to do.

Ok this video gives you an idea of how my implementation works. In my case, since it is in space with no gravity, I want it to feel a little more sloppy. If I wanted it to be really tight like yours I would dial up the damping and dial up the force.

I show an example of how it reacts when you move it fast, bump it against other physics actors and how it reacts when it bumps against an immovable actor so you can see the differences.

Let me know if this looks like the right direction for what you are trying to do.

Thank you very much for trying to help me! Your game looks amazing! I hope you can manage to complete it and it’ll find success! :smiley:
I like your implementation a lot. I think it would take quite a lot of modification of other mechanics I have implemented in my game, and I think that’s just too much work for what I’m trying to achieve. The line trace in front of my character is used for other mechancis, and I couldn’t really afford changing that trace without it breaking a lot of other things.

Fortunately my issue got solved. I’m not 100% sure why though, but you did lead me down the right path. You assumed that ground friction was messing with the velocity, and I think you were right. That must happen right after I copy the velocity of the pawn. So what I did was turn off gravity of the actor when the pawn is in the push/pull state. This seems to stop the ground friction from being calculated, even if there is a collision with the ground. I also found another solution, which would be to lift the actor ever so slightly above the ground when moving, this also avoids any ground friction.

Thank you for helping me, I truly appreciate it!

1 Like