I have a simple script to make an object spin: [![Script in inspector][1]][1]
Spin Speed is the speed to rotate the object on each axis (preferably in degrees per second). Local is whether the rotation should be done based on world axes or object axes. Starting Rotation is the initial rotation of the object.
Normally I would use Transform.Rotate to do the rotation, but in this case I have to make the rotation a function of time, so you can pass in any time value and it will return what the rotation should be at that time.
Here is an example (this doesn't work properly for either world or object axis rotation):
private Quaternion getRotation(float time) { return Quaternion.Euler(InitialRotation + SpinSpeed * time); } I just need some help figuring out the math behind calculating rotations for both world and object axes. I think that matrices can be used but I honestly don't remember anything about how to use them.
Edit: I had Here's an epiphany as to how I could kindexample of hackusing world axes with a solution that uses Transform.RotateSpinSpeed of 180 on the y axis and an initial rotation of 45 on the x axis: https://i.gyazo.com/d7f41b6a88425b5d8b8237cd7ac40878.gif
//Save rotation at the start of the frame Quaternion rot = transform.rotation; //Set rotation to InitialRotation transform.rotation = Quaternion.Euler(InitialRotation); //Perform rotation transform.Rotate(SpinSpeed * time, Local ? Space.Self : Space.World); //Save the calculated rotation Quaternion targetRot = transform.rotation; //Reset rotation to what it was at the start of the frame transform.rotation = rot; //Set rigidbody rotation to target rigidbody.MoveRotation(targetRot); I won't close this just yet in case someone can answer with a less-hacky wayAn example of doing this. Otherwise I will close this question if I don't get any answers. [1]using local axes with the same parameters as above: https://i.sstatic.net/a7w9r.png https://i.gyazo.com/d453b3dd239c9f77b86ce372c499d068.gif