For the context: The players are in a ship that travels at highspeed in the world. The players should be able to move inside the ship while it’s travelling.
If there is only the floor moving and the players stay still in the ship, everything is fine. If a player move towards another player a collision occurs with the other player. I found this out by adding a log printing the name of the component colliding with the player capsule component. With this log I also find out that a player can collide with walls if I add some to my moving ship.
I don’t know what to do, I tried a few things to fix this issue but nothing worked. If anybody has an hint on this, it would be great!
If a player move towards another player a collision occurs with the other player.
Sounds like a reasonable thing to happen no?
The character movement component will in general move with the base it’s standing on. So as long as the player is standing on a valid base I would expect collision to work normally.
What is a little bit problematic is jumping on moving platforms. What I added in past projects was that I keep the connection to the base active so that the player keeps moving with the speed of the platform. Was used for example to stay in sync with a moving train.
For the jump, I simply check the box “Stay Based in Air” in the CharacterMovementComponent in the “Character Movement: Jumping / Falling” section.
For the collision problem, let’s assume that there are 2 players based on my moving platform. They are both moved with the platform. If Player 1 move towards Player 2 while the platform is moving, a collision occurs on Player 1. This collision add an impulse on Player 1 who is ejected from the platform, even though the Player 2 didn’t move on the platform.
I see the same behavior when moving close to a wall or an object that are in the same BP as my platform.
Here are videos of what’s happening when moving near an object which isn’t the player base:
With players:
With walls:
I did another test yesterday with Simulated Physics checked on the root of my BP (i.e. my platform) and with the “Auto Weld” option check on all my walls, it seemed to avoid collision with walls but had strange behavior with the player placement. I also had to add angular constraints to prevent the platform from rotating when players spawned on it, and it will be a problem for the futur since I want this platform to rotate later. And also this solution don’t fix the players collision.
I have some new information. I have this behavior only with spawned walls. The walls you can see in the videos are spawned in c++. If I add a StaticMeshComponent in my platform BP it works fine, so what I said in my previous message is complete bullsh*t. These walls must be spawned as they are randomly generated. I tried to set the ship as the owner of the walls but it didn’t do anything.
First, for the walls I found a fix by using the UObject::Rename method to set a new outer for the walls. I assume that the player movement due to the base movement ignore components with the same outer as the base (I tried with the owner but it didn’t worked). Maybe it’s a bit dirty but it works, and since the walls I spawn won’t be updated later, I feel like it’s no big deal.
Last thing I did is to create my own CharacterMovementComponent, override the SetBase method with an empty method, and compute the new player location manually. It seems to fix both the collision between players and with walls (I disabled the solution I mentionned above).
I placed break points in HandleImpact, but sometimes it was triggering and sometimes not, at least never when the collision between players happened