maronvert Posted April 9, 2014 Share Posted April 9, 2014 Hello everybodyI have a mesh that starts on a certain position. Now every 5 seconds I want it to move to another x-position.All the positions the mesh should go are stored in an array.How can I make the mesh move to a random position that's specified in the array? var array=[10, 20, 15, 30, 45,] So for example it starts at mesh.position.x = 10 next (after 5 seconds) it should go to mesh.position.x = 30 then mesh.position.x = 15 and so on. just randomly.I already know how to write the code for the 5 seconds but how can I make it change randomly? Thanks Quote Link to comment Share on other sites More sharing options...
binyan Posted April 22, 2014 Share Posted April 22, 2014 var index = Math.floor(Math.random()*array.length); mesh.position.x = array[index]; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.