telal
October 21, 2014, 11:43am
1
ould you please help me! I need to turn the gameobject on 45 degrees without rotation. I need to change it angle only.
I’m trying to use code
float angle = Mathf.MoveTowardsAngle(gameObject.transform.eulerAngles.z, 45f, 10 * Time.deltaTime);
gameObject.transform.eulerAngles = new Vector3(0, 0, angle);
but it rotates the object around the center
Try to go in to your 3D modelling program and turn the mesh 45 Degrees. If you are working in blender, just go into edit mode, select mesh and press r + z + 45 and save it.
I you want to rotate game object with out rotation, you can try Rigidbody.AddTorque and angular drag for rotation.Unity - Scripting API: Rigidbody.AddTorque