I have a sphere script that on collision it instantiates a cylinder (object3), then once the cylinder appears, the cylinder is supposed to rotate some way, the direction of rotation doesn't matter. But the code I have is not getting the cylinder to rotate. I've tried different lines of code and tried putting the quaternion lines in the update function and in the on collision function but neither way gets the cylinder to rotate. I am not sure if it has to do with my code at this point, or if I have to do something within unity 3d settings. Any suggestions?
public class sphereBehavior : MonoBehaviour
{
public GameObject object3;
private Vector3 direction = new Vector3(-1, 0, 0);
private Vector3 rotateDirection = new Vector3(0, 0, 1);
// Update is called once per frame
void Update()
{
transform.Translate(direction * Time.deltaTime, Space.World);
transform.Rotate(rotateDirection, Space.World);
Quaternion Cylinder = Quaternion.Euler(90,50,69);
transform.rotation = Quaternion.Slerp(transform.rotation, Cylinder, Time.deltaTime);
}
//void OnCollisionEnter(Collision collision) => Instantiate(object3, new Vector3(0, 1, -2), Quaternion.identity);
void OnCollisionEnter(Collision collision)
{
Instantiate(object3, new Vector3(0, 1, -2), Quaternion.identity);
Destroy(collision.gameObject);
}
}
it is supposed to rotate some wayWhat is "it," the cylinder or the object this script is attached to? Because right now you're rotating the object this script is attached to.