RotateAround object around player when pushing button.

Hello,

Im trying to write a code where a blueCube rotates around a redCube horizontally when pushing the left and right arrow keys and vertically when pushing the up en down keys. neither of them have rigidbodies. I created the code down below, and it seems to work fine if I move only in a horizontal or on a vertical line. But If I combine them The blueCube does not fully rotate around the redCube, but makes circles beside it or rotates round itsself (hopefully you understand what I mean, kinda hard to explain^^). So my questions are:

a. How can I make it that the rotation does work like the blueCube Rotates the redCube the right way?

b. How can I make it so that the blueCube can not sink in the ground when moving it vertically (the -y axis relative to the position of the redCube)?

Many Thanks for helping me out!

My code:

using UnityEngine;
using System.Collections;

public class BlueCubeMovement : MonoBehaviour {
    public Transform redCube;
    public float moveSpeed;
    private float inputVertical;
    private float inputHorizontal;
    private float movementVertival;
    private float movementHorizontal;

	void Update ()
    {
        float inputHorizontal = Input.GetAxis("RotateHorizontalBlue");
        float movementHorizontal = inputHorizontal * moveSpeed * Time.deltaTime;
        transform.RotateAround(redCube.position, Vector3.up, movementHorizontal);

        float inputVertical = Input.GetAxis("RotateVerticalBlue");
        float movementVertical = inputVertical * moveSpeed * Time.deltaTime;
        transform.RotateAround(redCube.position, Vector3.forward, movementVertical);
    }
}

a. If you want to rotate vertically, you should use blue cube’s local x axis, not global. Like this:

transform.RotateAround(redCube.position, transform.right, movementVertical);

b. I don’t know if i understand you correctly. To make it not sink into the ground just check it’s Y position and make sure it’s not lower than ground (i assume that ground Y position is 0). Type this at the end of Update() function:

if(transform.position.y < 0)
			transform.position = new Vector3(transform.position.x, 0, transform.position.z);