Reputation: 51
I have a ball that I would like to apply an impulse to. This I know how to do. What I don't know how to do is randomize the direction of the ball. How would this be done.
Upvotes: 0
Views: 177
Reputation: 4423
The way to generate random float:
func randomFloatBetween(lower: CGFloat, upper: CGFloat) -> CGFloat {
return CGFloat(arc4random()) / CGFloat(UINT32_MAX) * (upper - lower) + lower
}
Use it to make your random CGVector
.
Upvotes: 1