script to place models on slopes

Hello there,

Just wondering, is there a script to place lets say 8 models on slopes randomly? Like, if the slope is over 10 degrees, places X models randomly. Have a ton of rock to place and would like a more simple way of doing it. This is in the editor also, just click it, run it and it goesthen done.

you can do a raycast at random places. a RaycastHit returns the normal of where it hits with the info you need.

I have the angles etc, I just was wondering if there is something out there like a script that you enter your models and it will place them. For instance, I need these pathways (Screenshot - c0df73f5cc40d8b0cbce522a298b5f17 - Gyazo) covered with rocks on the walls, instead of placing them one by one, a script that places tem for me once and iā€™m done.

you could do something simple like this

using UnityEngine;
using System.Collections;

public class PlaceRandomModel : MonoBehaviour {

    public GameObject[] models;

    // Use this for initialization
    void Start () {
   
    }
   
    // Update is called once per frame
    void Update ()
    {
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;
        if(Input.GetMouseButtonDown(0))
        {
            if(Physics.Raycast(ray, out hit, Mathf.Infinity))
            {
                int index = Random.Range(0, models.Length);
                GameObject clone = (GameObject)Instantiate(models[index], hit.point, Quaternion.identity);
                clone.transform.up = hit.normal;
            }
        }
    }
}

you could complete it with assigning a tag to the instantiated models and check for the tag in the raycast for deleting misplaced modelsā€¦

I use MegaScatter for this sort of thing, allows me to define areas to scatter into, use height limits to define regions or slope angles to scatter on to, saves me a ton of time building my levels, plus I can change the settings and re scatter depending on the platform and also the biggest feature for me is being able to scatter at runtime which took my mobile apps memory size down by over 100MB.

1 Like

edit: ā€œstupid commentā€ ā€¦ :-p

Well I was responding to the original poster so the post was not meant for you, and he asked if there was a ā€˜scriptā€™ not how to do it.

sorry didnā€™t mean to offend you.
youā€™re right stupid comment, didnā€™t look good, thought you where the original poster.
but still why not try things yourself and learn in the processā€¦