Orbiting around local axis

I’m trying come up with a script that will orbit an object around a target, much like the mouseOrbit script that comes with unity, but I need mine to use the orbiting object’s local axes as the rotation axes.

In mouseOrbit the rotation is calculated this way:

var rotation = Quaternion.Euler(y, x, 0);

but the problem with this is that it will always rotate around absolute world axis so when I’m directly on top of the object it will start to roll instead of orbit which is not the result I’m looking for.

so I tried this:

var xRot : Quaternion = Quaternion.AngleAxis(x, transform.up);
var yRot : Quaternion = Quaternion.AngleAxis(y, transform.right); 
var finalRot : Quaternion = yRot * xRot;

But it goes all crazy as I rotate.

Can anyone give me a hand? I think I’m close I just need to figure out how to properly combine the rotations.

Ok scratch that, that won’t even work when is not freaking out. I guess I’m really stuck here. I want to be able to rotate an object the same way I do in the unity editor just can’t find the right way to do it. Anyone know a way that would like to share?

Ok, so I had to use transform.Rotate it was that easy, can’t belive I didn’t think of it.