rotating around parent's axis?

the problem here is sort of tricky. im trying to make a marble based game, think, marble blast, marble madness, etc. I want the sphere to rotate in the direction of its movement. if i tell it to rotate on its own y axis, then its x axis will get messed up, so when i move left, the sphere rotates in weird directions. i just want simple “push left, move left” controls, with realistic rolling of the sphere. heres what I have:

//sphere roll script
function Update () {
var Forespeed = Input.GetAxis (“Vertical”) * PlayerStats.Speed;
var Sidespeed = Input.GetAxis (“Horizontal”) * PlayerStats.Speed;

transform.localRotation (Forespeed, 0, Sidespeed);

}

also, using global axis is also not possible as the direction the “up” key moves is dependent on the camera’s angle. really, im trying to rotate the sphere along the camera’s axis. any help is greatly appreciated.

sorry, that last line is

transform.Rotate (Forespeed, 0, Sidespeed);

not

transform.localRotation (Forespeed, 0, Sidespeed);

still looking for help with this. second post was only fixing a typo.

You can use camera.transform to get the camera’s transform, then choose an axis for your rotation. Look at getting camera.transform then using the camera’s right and forward axes (will be provided in world-relative space). Here’s a quick hacked together and untested example of the direction I’m thinking you might consider:

var sideRoll = CameraRef.transform.right * Sidespeed;
var frontRoll = CameraRef.transform.forward * Forespeed;
var totalRoll = sideRoll + frontRoll;
transform.Rotate(totalRoll, Space.World);

Or something like that. Basically you can get at the camera’s axes via its transform, and from there you should be able to cook something up.

I hope that helps!

:smile: ! Very nice! Thanks again, Higgy. Seems like everytime i post, you come to my rescue. your suggestion was sideways, but i fixed in in under a minute. here’s the working script if anyone is interested.

var CameraRef : Transform;

function Update () {
  var Forespeed = Input.GetAxis ("Vertical") * PlayerStats.Speed;
  var Sidespeed = Input.GetAxis ("Horizontal") * PlayerStats.Speed;
  var sideRoll = CameraRef.transform.forward * Sidespeed * -1; 
var frontRoll = CameraRef.transform.right * Forespeed; 
var totalRoll = sideRoll + frontRoll; 
transform.Rotate(totalRoll, Space.World);
}

That’s just how I roll! </bad jokes> :stuck_out_tongue:

I’m glad to be of service, keep on rockin’ it!