Rotating an object to avoid intersection

Hi all,

I have a cuboid. The cuboid is being pushed forwards at a certain amount per frame and will eventually hit a wall. I’d like to rotate the cuboid (around its centre) enough for that particular frame’s movement to complete without the cuboid intersecting the wall.

Here’s where I’m at with problem solving:

I know a bunch of things about the above image:

  • The amount we’re trying to move forwards into the wall (a)
  • The target location of the cuboid
  • Hit Location
  • Hit Normal
  • Distance from the cuboid’s origin at the time of the hit to the Hit Location (b)
  • The angle between the cuboid’s direction of travel and the Hit Location (c)
  • Aaaaand a bunch more.

I feel like the solution is to find angle D, which is the rotation required to move the point of the hit on the cuboid back outside of the wall but there could well be another way to tackle it.

Why not just use physics?

My experience with the physics system so far has been pretty unpredictable and I’m moving some of this stuff quite fast. Plus it’s an interesting learning experience!