Jump to content

How to randomize Object position? SOLVED


Recommended Posts

Greetings Forum, I hope you have a great day :)

Today, I would like to ask how to randomize position in babylon.js. I have one Apple object which i would like to randomize its position everytime i touch it. 
Here's a screenshot of what my game looks like. As can be seen, I am trying to randomize the apple position to make it more like point collecting game.

I'm trying to follow tutorial here
But the program crashed, and wont work :)  ...

Any Attention or solutions will be greatly appreciated, cheers :)

P.S : I tried to upload it to playground, but it seems not working because my apple and sonic are on different files, hence i can only provide a screenshot to help the forum to understand my question , I'm sorry for my lack of knowledge :)

// Creation of Apple
			for(var i=0; i<20; i++) {
				 x = randomNumber(-100, 100);
				 z = randomNumber(-100, 100);

	            var apple2;
				BABYLON.SceneLoader.ImportMesh("","Finalproject/", "apple.obj", scene, function (newMeshes, particleSystems, skeletons) { 
	   				apple2 = newMeshes[0];
	   				apple2.position.x = x;
	   				apple2.position.z = z;



Link to comment
Share on other sites

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.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...