I have a transport ship that you can walk around on. I have an empty game object as a parent for both the “ship” (currently a flat cube as floor) and the unit. Selection and ordering works fine and you can order the unit around like in a normal RTS-game.

There are two problems however, first of all the movement isn’t relative by nature so if I right-click somewhere and the entire ship moves, it’ll try to move to the target location in world space, not relative to the ship. I’ve fixed this by saving a relative vector and applying it when I move. It works great.

The other problem is quite similar. If I order my unit to move away to the right and I at the same time rotate the entire ship, the unit will keep going right while it should in fact be going slightly angled to get to it’s situation.

The obvious answer to this problem would be to just save a relative vector and move towards that one each time, but the problem becomes more complex since I’m combining this with A*. I’ve already set it up so the grid graph is updated as the possible interior walls on the ship move with the ship. The problem is that I cant just calculate a single relative vector and use it every time I move since I get a vector array that I don’t want to recalculate each tick.

So what have I tried? Well, I feel like the correct approach would be to save the original rotation. Let’s pretend Unity uses normal angles instead of Quaternions. Let’s say the original path was calculated when the ship was rotated 200 degrees. Now in the update loop, I check the current ship rotation. Let’s say it’s changed to 250 degrees, I then rotate the current vector in the vector path by 50 degrees.

To translate that to Quaternions, I’ve been doing: “OriginalParentRot = Parent.transform.rotation” and then multiplying my relative vector with: “NewPosition = Quaternion.Inverse(OriginalParentRot) * Parent.transform.rotation * NewPosition”

So I basically undo the old rotation by using the Quaternion inverse and then I apply the new parent rotation. However, this doesn’t work. It compiles fine but it doesn’t seem to have an effect.

I feel like I’m rambling at this point. Am I approaching it the right way? Ideas?