Have a tank that can move around and shifts to match the normal of the terrain under it. On top of that is a turret that rotates around the tanks local Y axis, sticking out of that is a barrel that should match the turrets rotation and have its own rotation up and down.
I can never seem to get the barrel to do everything I need. Either its deformed but moves right or it looks right but the shifting to match normals throws it out of position.
Current attempt:
public void SetRotation(float a, float aim)
{ // set tank rotation
Vector3 offset = new Vector3(direction.X * 0.5f, direction.Y + 1.75f, direction.Z * 0.9f);
Vector3 normal = myGame.getNormals((int)tank.getPosition().X + gDim / 2, (int)tank.getPosition().Z + gDim / 2);
worldRot = Matrix.CreateRotationX(normal.X) * Matrix.CreateRotationY(normal.Y) * Matrix.CreateRotationZ(normal.Z);
worldRot *= Matrix.CreateFromAxisAngle(worldRot.Up, a) ;
worldRot *= Matrix.CreateTranslation(-offset) * Matrix.CreateFromAxisAngle(worldRot.Right, aim) * Matrix.CreateTranslation(offset);
}
Works fine on level terrain but as soon as I get to a slope it all goes wrong. Tried moving the offsets to the whole set of rotations but that went really weird. Tried rotating the offsets to match the new normal but that also went weird.
Lavan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.