Example #1
0
    private void PlantGameObjectToLandscape(GameObject obj, float splinePos, float faceSplineNormal)
    {
        float oldZ = obj.transform.position.z;

        obj.transform.position = landscapeSpline.GetPositionWorldSpace(splinePos);
        obj.transform.position = new Vector3(obj.transform.position.x, obj.transform.position.y, oldZ);
        obj.transform.LookAt(obj.transform.position + transform.forward, (landscapeSpline.GetNormalInterpolated(splinePos) * faceSplineNormal + Vector3.up * (1f - faceSplineNormal)).normalized);

        if (obj.name == "Rock")
        {
            obj.transform.position += new Vector3(Random.Range(-4f, 4f), Random.Range(0f, 5f), 0f);
            obj.GetComponent <Rigidbody>().velocity = new Vector3(Random.Range(Mathf.Clamp(-0.01f * transform.position.x, -60f, 0f), 0f), 0f, 0f);
        }
    }