HAJFAJV
November 19, 2019, 10:31pm
1
So I have some spheres in 2D.
I want them to be rotated before they instantiate, because they have a velocity applied to them and I want them to go in random directions.
Right now nothing happens, but if I was to take transform.Rotate(new Vector3(0, 0, Random.value * 360) * Time.deltaTime); and stick it into void update they are going to spin around themselves.
Why is this rotation not applied to the orbPrefab?
private float forcef = 150;
private Rigidbody2D orb;
private void Awake()
{
orb = GetComponent<Rigidbody2D>();
orb.velocity = transform.right * Time.deltaTime * forcef;
}
private void spawnOrb()
{
GameObject orb = Instantiate(orbPrefab) as GameObject;
transform.Rotate(new Vector3(0, 0, Random.value * 360) * Time.deltaTime);
a.transform.position = new Vector3(0, Random.Range(-4,4), 0);
}
HAJFAJV:
So I have some spheres in 2D.
I want them to be rotated before they instantiate, because they have a velocity applied to them and I want them to go in random directions.
Right now nothing happens, but if I was to take transform.Rotate(new Vector3(0, 0, Random.value * 360) * Time.deltaTime); and stick it into void update they are going to spin around themselves.
Why is this rotation not applied to the orbPrefab?
private float forcef = 150;
private Rigidbody2D orb;
private void Awake()
{
orb = GetComponent<Rigidbody2D>();
orb.velocity = transform.right * Time.deltaTime * forcef;
}
private void spawnOrb()
{
GameObject orb = Instantiate(orbPrefab) as GameObject;
transform.Rotate(new Vector3(0, 0, Random.value * 360) * Time.deltaTime);
a.transform.position = new Vector3(0, Random.Range(-4,4), 0);
}
You are rotating the spawner instead of the orb
Try changing
private void spawnOrb()
{
GameObject orb = Instantiate(orbPrefab) as GameObject;
transform.Rotate(new Vector3(0, 0, Random.value * 360) * Time.deltaTime); //this
a.transform.position = new Vector3(0, Random.Range(-4,4), 0);
}
For this
private void spawnOrb()
{
GameObject orb = Instantiate(orbPrefab) as GameObject;
orb.transform.Rotate(new Vector3(0, 0, Random.value * 360) * Time.deltaTime);//for this
a.transform.position = new Vector3(0, Random.Range(-4,4), 0);
}
You can also add the rotation to the Awake
private void Awake()
{
transform.Rotate(new Vector3(0, 0, Random.value * 360) * Time.deltaTime);
orb = GetComponent<Rigidbody2D>();
orb.velocity = transform.right * Time.deltaTime * forcef;
}