# How can I rotate a collision object in code?

**URL:** <https://forums.unrealengine.com/t/how-can-i-rotate-a-collision-object-in-code/292683>\
**Category:** World Creation\
**Tags:** rotation, unreal-engine, Collision, question\
**Created:** [September 2, 2014, 4:13pm UTC](https://forums.unrealengine.com/t/how-can-i-rotate-a-collision-object-in-code/292683 "2014-09-02T16:13:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thumper](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Thumper](https://forums.unrealengine.com/u/Thumper)\
**Post date:** [September 2, 2014, 4:13pm UTC](https://forums.unrealengine.com/t/how-can-i-rotate-a-collision-object-in-code/292683/1 "2014-09-02T16:13:10Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Pierdek](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Pierdek](https://forums.unrealengine.com/u/Pierdek)\
**Post date:** [September 2, 2014, 4:24pm UTC](https://forums.unrealengine.com/t/how-can-i-rotate-a-collision-object-in-code/292683/2 "2014-09-02T16:24:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Thumper](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Thumper](https://forums.unrealengine.com/u/Thumper)\
**Post date:** [September 2, 2014, 4:29pm UTC](https://forums.unrealengine.com/t/how-can-i-rotate-a-collision-object-in-code/292683/3 "2014-09-02T16:29:16Z")

</div>

Awesome this worked perfectly.

---

<div class="post-metadata">

**Author:** ![Thumper](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Thumper](https://forums.unrealengine.com/u/Thumper)\
**Post date:** [September 2, 2014, 4:30pm UTC](https://forums.unrealengine.com/t/how-can-i-rotate-a-collision-object-in-code/292683/4 "2014-09-02T16:30:58Z")

</div>

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!
