Jump to content
This site uses cookies! Learn More

This site uses cookies!

armedunity.com uses cookies to improve user experience.

By continuing to use this site, you agree to allow us to store cookies on your computer.

  • 0
Sign in to follow this  
V3ndetta

Random placement algorithm coordinate managing problem

Question

Working on my portofolio, trying to make procedural generation systems, but I have run into the following problem: I need to divide x and z coordinates of my floor size to keep my spawned items inside it's limit, but this will result items being only spawned in one 4th of the plane(the floor), negative coordinates being ignored. I think I could overcome this problem by making a second for statement for the negative x and z axes, but I was wondering if anyone who has done something similar knows if there another way I should use in this case?

 

Please login or register to see this code.

 

Thanks in advance.

Share this post


Link to post
Share on other sites

3 answers to this question

Recommended Posts

  • 1

Please login or register to see this attachment.

Same thing but using the bounds of the mesh renderer for objects that may contain a mesh larger/smaller than 1,1,1 world scale. Image above shows 1000 coins instantiated:

 

Please login or register to see this code.

 

Share this post


Link to post
Share on other sites

  • 0
Please login or register to see this code.

By looking at your code and seeing your manipulating based on scale, I am guessing all of your obsticals are going to be cubes or something (mesh world scale of 1, 1, 1) and that the pivot is in the center. If your using things that the mesh is larger than 1, 1, 1 in world scale, then calculating based on transform scale is not going to work, you will instead need to access the mesh renderer and adjust it based off of it's render bounds instead of local scale.

 

But here is your fix in js, didn't feel like typing it up in c#

Share this post


Link to post
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.

Guest
Answer this question...

×   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.

Sign in to follow this  

×
×
  • Create New...