- Home /
Make an object rotate instantly upon an event occuring in C#
I'm trying to make a die spin at random speeds when it is created to simulate a roll of a die (it will spawn, start spinning, and fall down to collide with a plane below). I have everything working...except I can't get the die to spin. I don't need help with generating the random numbers, so for simplicity I removed RNG from my code for the time being. Here is what I have:
using UnityEngine;
using System.Collections;
public class Spin : MonoBehaviour {
void Create()
{
transform.localRotation = Quaternion.Euler (150, 250, 200); //arbitrary values
}
// Update is called once per frame
void Update () {
}
}
This doesn't work at all. The die spawns, falls, and collides with the plane below just fine. It just doesn't spin.
instead of the Euler method, I also tried:
transform.Rotate (Vector3.up, speed * Time.deltaTime);
transform.Rotate (Vector3.right, speed * Time.deltaTime);
transform.Rotate (Vector3.forward, speed * Time.deltaTime);
which did not work either. What changes to the above code do I have to make to make it spin properly?
Answer by njpatter · Feb 05, 2014 at 04:04 PM
You should give it an angular velocity. All of the versions that you have included are instantaneous rotations that you likely will not be able to see.
Your answer
Follow this Question
Related Questions
Opposite angle rotation 0 Answers
Get slerp to work just as LookAt(,Vector3.right) does 1 Answer
How to use quaternion.lerp 2 Answers
Boids for 2D 0 Answers
Rotate object without storing facing 1 Answer