How can I rotate a collision object in code?

FQuat::Identity change this parameter it rotating collision shape.

1 Like

I’ve finally resolved a lingering issue with my CharacterMovementComponent to allow my character to walk around on the walls and ceiling inside of a sphere. The character was entering a state of falling and not leaving it when he was at a perfect 90 degree wall. The issue ended up being that in ComputeFloorDist

bBlockingHit = GetWorld()->SweepSingle(Hit, CapsuleLocation, CapsuleLocation + hkvCompToWorld(FVector(0.f, 0.f, -TraceDist)), FQuat::Identity, CollisionChannel, CapsuleShape, QueryParams, ResponseParam);

the collision object CapsuleShape did not update with my character capsule rotation. So at the 90 degree wall the collision capsule shape was still in it’s Z is up state which would put it’s side parallel to the ground the character was walking on. To fix this I changed the shape to a sphere. This fixed the problem, so now I want to return it to a capsule shape but instead have the capsule oriented properly.

FCollisionShape CapsuleShape = FCollisionShape::MakeCapsule(SweepRadius, PawnHalfHeight - ShrinkHeight); 

How can I rotate the collision object created above?

Awesome this worked perfectly.

Per Pierdek’s advice I Changed the Sweep Single to this:

bBlockingHit = GetWorld()->SweepSingle(Hit, CapsuleLocation, CapsuleLocation + hkvCompToWorld(FVector(0.f, 0.f, -TraceDist)), FQuat(CharacterOwner->GetActorRotation()), CollisionChannel, CapsuleShape, QueryParams, ResponseParam);

The difference is that the FQuat::Identity can also take a FQuat( Rotator ) so I used the CharacterOwner->GetActorRotation() to feed it a rotation. Works!!! Thanks!

1 Like