Spawning Meteors above a sphere
Im working on a doge Meteor game im having trubble with randomly spawning my meteor prefab. im looking to have meteors spawn above a sphere / planet and come falling down. i can get them to sapwn but there not spawning above the planet. im using this code:
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class MeteorSpawner : MonoBehaviour {
public GameObject meteorPrefab;
public float distance = 20f;
void Start()
{
StartCoroutine(SpawnMeteor());
}
IEnumerator SpawnMeteor()
{
Vector3 pos = Random.onUnitSphere * 20f;
Instantiate(meteorPrefab, pos, Quaternion.identity);
yield return new WaitForSeconds(1f);
StartCoroutine(SpawnMeteor());
}
}
the meteor prefab is uisng a FauxGravityBody which is this code: using System.Collections; using System.Collections.Generic; using UnityEngine;
[RequireComponent(typeof(Rigidbody))] public class FauxGravityBody : MonoBehaviour { private FauxGravityAttractor attractor; private Rigidbody rb;
public bool placeOnSurface = false;
private void Start()
{
rb = GetComponent<Rigidbody>();
attractor = FauxGravityAttractor.instance;
}
private void FixedUpdate()
{
if (placeOnSurface)
attractor.PlaceOnSurface(rb);
else
attractor.Attract(rb);
}
} any help would be grateful
Your answer
Follow this Question
Related Questions
Random spawn script 1 Answer
Rotate smoothly on sphere 2 Answers
Planes to Sphere Issue 0 Answers
2D ball rolling animation 0 Answers
Making an endless hallway with random objects spawning 0 Answers