# Constraint two pawns together

Hi,

Currently I’m struggling to constrain two pawns each controlled by a different player. The effect I would like to have as if the are holding hands for example, if one moves the other one is “dragged” behind him, if both move in the same direction they just move and if both move in opposite direction they don’t move at all as they both try to move away from each other.

The effect in the game happens when the player is shot with a “sticky” projectile it attaches to the hit player. As soon as another player collides with the sticky projectile as well they should be “glued” together.

My first attempt was to do it via a force that pulls them towards each other based on the distance between them, but that was feeling weird and on top of that as the other pawn was not moving the player moving away was “slowed” down by the still standing player.

Is there a way to connect them somehow using a physics constraint, but I guess i would need to enable physics then which will lead to other weird effects I assume.

Any help would be appreciated.

I would not use physics for that, even if you mange to get it working it would have lots of weird side effects. Assuming you use Characters and Character Movement, I would use the other players movement input to calculate the current players input. You could calculate the vector in the middle of both direction to get the movement input for both players. Then you could use the dot product to calculate the speed, if the movement inputs point in opposite directions the speed would be zero, full speed if they point in the same direction.

When this is done you could try to smooth the movement by taking account the distance between the players so they could move freely in close distance without dragging the other player.

Of course this approach would only work for the movement, if one player jumps or falls they would seperate, you need to handle this cases too. Move the other player towards the falling player for example, so it feels like is he is dragged down too.

mhh that sounds interesting…

just one follow up question, to set the movement input vector to the direction between both inputs, I would need to consume the input vector first and add the in-between vector as the input direction via the Add Input Vector to get it to work, right?

And… now that I think of it, wouln’t that same approach work with just the velocity vectors instead of the input vectors? this would solve the falling/jumping

thanks i will try that

If it’s something like a sticky projectile, you could most likely set the projectile’s parent transform to the player. That way it would automatically be moved whenever the cintrolled actor moved. You could even (or really should) disable physics on the projectile at that point.

You are basically right, I would store the input vector you get from the input event in a variable or you could get it directly from the Get Axis Value node of your input Axis, then you can calculate the movement in the tick event and add it as a input vector to your character movement.

It could also work, if you add a force to your movement, if you override the characters velocity it won’t fall.