- Home /
What is the best way to evenly distribute objects to fill a curved space?
I have been struggling to find an elegant way to fill this seating area with chairs. I've tried using splines, but I still end up having to do a lot of individual rotation to orient all the chairs towards the same focal point. Is there a better way to go about this? Any help would be greatly appreciated, I've been at this for days...
UPDATE: I found this code which has taken care of rotating the chairs so they target the same focal point. But I'm still curious if there are any better methods to do this.
//C# Example (LookAtPoint.cs)
using UnityEngine;
[ExecuteInEditMode]
public class LookAtPoint : MonoBehaviour
{
public Vector3 lookAtPoint = Vector3.zero;
void Update()
{
transform.LookAt(lookAtPoint);
}
}
Are there any areas covered by itself (from the top direction) If the answer is no, I think you could just Raycast down from several points (possibly just a square grid of points) and spawn a chair wherever a raycast hits something on the ground layer. Let me know it you want the code for this.
Also note that your transform.LookAt function will rotate the chairs in all directions. If these are swivelling chairs, it may be preferable to turn them only on the y axis, which you could use Quaternion.LookRotation.eulerAngles.y
If the problem is positioning the chairs, then it depends if you want to hand place it or procedurally. You can attempt what I outlined in the comment (raycasting to check it above the ground), but you're going to have to find some rule about how you want to arrange the chairs. If you give me an image of the arrangement you want, I might be able to help.
Answer by AshAbeAdd · Apr 10, 2017 at 12:43 PM
Looks interesting. I'm not that experienced of a coder, but I was working on some waypoints about a week ago. While putting waypoints down, you can have vehicles move and rotate as require. Now I don't know how complicated you want to make your codes and seating arrangement, but it's definitely something you should look into. Maybe make several starting points in which you can add a bool if space is taken up, then you just need to draw the starting point to where you're looking at. You probably want to make sure that it doesn't move though. lol