Spawned objects won't move in correct direction.
So I don't know what happened, but this script was working perfectly fine before. After doing a little work in a different area of the code I must have accidentally changed something in this. The goal is when the meteor object is spawned into the world, it will have a random rotation and random velocity. I use transform.up to make the meteor to travel in the angle it has spawned in, but for some reason, it has stopped. Here is the code: public Rigidbody2D rb; public Transform tForm; public GameObject MeteorSprite; public float minSpeed = 4f; public float maxSpeed = 7.5f; public float rotateN = 15f;
//add movement and rotation
void Start()
{
//sets speed
rb.velocity = transform.up * Random.Range(minSpeed, maxSpeed) * -1;
//sets angle
tForm.Rotate(new Vector3(0f, 0f, Random.Range(rotateN, -rotateN)));
}
Your answer
Follow this Question
Related Questions
MovePosition/Velocity not following a direction 0 Answers
C# keep previous velocity while jumping, previous solutions not working 0 Answers
How does rigidbody velocity works? 1 Answer
Keep getting Error CS0131 1 Answer
Mount and Blade Combat System Attacking The Same Direction When Going A Different Direction 0 Answers