lundi 30 janvier 2017

Random direction en 2D lua

I want to create a random direction for my sprite, in Lua 2D.

So, i've tried that :

Sprite.x = Sprite.x + vx
Sprite.y = Sprite.y + vy

Sprite.vx = math.random(-1,1)
Sprite.vy = math.random(-1,1)

So, i managed to create a random direction, but my problem is the speed of the sprite, is directly linked to the number of direction. For example if i want the speed to be 1, it can only have 4 direction. I made a sprite with a lot more, by setting the random speed between -3 and 3, but then it's faster than what i want.

What should i do?

I've seen a few posts talking about random direction, but the description wasn't about lua and i couldn't really understand it..

Thanks!




Aucun commentaire:

Enregistrer un commentaire