- Home /
How to rotate ?
Hi, I have this script
public class Gravity : MonoBehaviour
{
public Transform planet;
public float fallSpeed = 5;
// Update is called once per frame
void Update ()
{
Vector3 direction = ( transform.position - planet.transform.position);
direction.Normalize();
//Vector3 rotation = new Vector3(direction, 0, direction);
transform.rotation = Quaternion.FromToRotation(transform.position, direction);
Debug.DrawRay(transform.position, -direction * 6, Color.green);
Debug.DrawRay(transform.position, Vector3.up * 3, Color.blue);
transform.Translate(Vector3.down * fallSpeed * Time.deltaTime);
//Physics.gravity = -direction;
}
}
As it is now, the ojects fall down the planet but I can not rotate them. So how can I do that ?
Answer by Sanky · Feb 12, 2013 at 06:04 AM
private void Update() { transform.Rotate(Vector3.forward Time.deltaTime 100); }
Answer by Imankit · Feb 12, 2013 at 05:27 AM
Use transform.Rotate... See..
file:///Applications/Unity/Unity.app/Contents/Documentation/Documentation/ScriptReference/Transform.Rotate.html
This don't work, because I use transform to rotate so all the time the down side of the object is pointing to the planet
transform.rotation = Quaternion.FromToRotation(transform.position, direction);
and right now every frame will rotate to the planet and will not rotate on y axis
so when I rotate towards the planet somehow I must bypass the y axis
Your answer
Follow this Question
Related Questions
Rotate AI towards target, on single axis? 1 Answer
Rotating a character's velocity? 3 Answers
Merge a rotation(vector3) to a lookAt(quaternion) ? 1 Answer
Trying to rotate player, how? 0 Answers