Download

character collision not working when stood still, works when moving

i’m trying to get characer collision to behave the same way when the character is still as it does when the character is moving. when my character is still moving objects move right through it and any collision that does happen is glitchy, when the character is moving collision is smooth. how can i get that to happen when my character is stoof still? the video below illustrates the issue:
https://youtube.com/watch?v=ou3lmURRZiY
i tried two examples, getting hit by a rotating pole moved by a rotating movement component, and a rotating pole manually updated in the actors tick. What am i missing to get my character to smoothly collide with the poles when they are standing still? i’m using UE4.25

I think this is a limitation of the character movement component. Move updated component detects collisions when moving but if the location delta is 0 there is no sweep distance.
If you want a quick fix you could try this within your movement comp tick function.



MoveUpdatedComponent(FVector(0.f, 0.f, 0.01f), UpdatedComponent->GetComponentQuat(), true);
MoveUpdatedComponent(FVector(0.f, 0.f, -0.01f), UpdatedComponent->GetComponentQuat(), true);


Thanks, i couldn’t add a custom charactermovementcomponent to the character so i tried updating movement through the component in the characters tick function like this:


GetMovementComponent()->MoveUpdatedComponent(FVector(0.f, 0.f, 0.01f), GetMovementComponent()->UpdatedComponent->GetComponentQuat(), true);
GetMovementComponent()->MoveUpdatedComponent(FVector(0.f, 0.f, -0.01f), GetMovementComponent()->UpdatedComponent->GetComponentQuat(), true);

which didn’t work, i’m really surprised Unreal doesn’t have support for checking collisions between a rotating actor and a still actor that isn’t simulating physics. I even tried just placing a static mesh actor (Cube - collision set to block all) and the rotating arms just move right through it.

I found a solution, but i could only get it working in blueprint. I followed the technique at the end ofthis post

I tried to re-implement this in c++ by adding this to Tick but it didn’t work, which is confusing me, did i miss something?


AddMovementInput(FVector(0.f, 1.f, 0.f)*0.1);
AddMovementInput(FVector(0.f, 1.f, 0.f)*-0.1);

Both methods should work. Where exactly did you put your code? Maybe share the whole function. I tried moving the updated component from the character tick in Blueprint against a rotating cylinder and it worked as expected. Blueprint or C++ should make no difference. Keep in mind that adding movement input like this might have unexpected effects since you are not undoing it right away but in the next tick.

Thanks, I hadn’t considered the movement wouldnt happen in the same tick, When i try and do it in the same tick i get really jerky movements compared to the two tick approach above. The full tick function is below, it is currently the only think i am doing. It is a subclass of ACharacter: I’m just trying to get smooth movements with Character that will interact well with both physics objects and objects that are moved by other means.e.g. Lerp


void APlayerCharacter::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);

AddMovementInput(FVector(0.f, 1.f, 0.f) * 0.1);
AddMovementInput(FVector(0.f, 1.f, 0.f) * -0.1);

}

and it produces this effect: https://youtu.be/il-pcZsqIVk

the second part of the video shows the effect when it is spread over 2 frames using the blueprint method outlined previously.


void APlayerCharacter::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);

AddMovementInput(FVector(0.f, 1.f, 0.f) * 0.1);
AddMovementInput(FVector(0.f, 1.f, 0.f) * -0.1);

}

This actually shouldn’t do anything because adding input and then immediately subtracting the same amount is the same as not adding anything in the first place.
The reason you get the glitching in the video is probably because of the depenetration mechanism built into the character movement component.
Also, your second rotating cylinder is placed quite low so it hits the underside of the capsule which probably has an effect on the FindFloor or MaintainDistanceToFloor functions, which is why the character kinda moves on top of the mesh.

Using MoveUpdatedComponent is really the better solution here. I tried it out in Blueprint yesterday and you said it doesn’t work for you in C++. I think the reason is that the Blueprint implementation calls SafeMoveUpdatedComponent internally which resolves initial penetrations as well (which can easily happen in your scenario).



FHitResult OutHit;
GetCharacterMovement()->SafeMoveUpdatedComponent(FVector(0.f, 0.f, 0.01f), GetActorRotation(), true, OutHit);
GetCharacterMovement()->SafeMoveUpdatedComponent(FVector(0.f, 0.f, -0.01f), GetActorRotation(), true, OutHit);


2 Likes

Bit late in getting back to you on this, apologies, i havent been able to get online. The code you suggested worked perfectly, thankyou!