How do you script an object to shoot like a comet (shooting star)?
So my main concern is being able to scatter a certain amount of gold coins onto a surface that is NOT flat, but on a sphere.
Here are a few tests I tried--
First Try : Place in a row and repeat I created the coin (I used a cylinder with a material). Once I placed the coin in the scene I duplicated the coin in one row around the sphere. After the row was completed, I duplicated the row and rotated it a few times. Every time I rotated a row of coins it would always appear in an oval shape. IN PLAY MODE: the player runs around in the scene and ALL the coins were above the player and it appeared like Christmas lights, but player could not reach them.
Second Try: use spawnpoints I made the coin as a prefab and used an instantiate function, the function works and the coins spawn, but the score stopped updating to the screen and was not disappearing when the player collided. The coin stretches and looks flat while rotating.
Third Try: At Runtime have the coin shoot to the spawnpoints Here is my third effort, since the coins refuse to stay on the surface of the sphere, I figured I can shoot the coins to there position and when the player hits the coins it will hide. However, my code says it has no errors but nothing is happening. I figured a shooting script would work. Would a raycast work if i were to calculate the distance between the coin and spawnpoint? I have tried OnCollisionEnter--nothing, I also tried the "Sphere overlay" within the physics -- i forgot the name. What I want the code to is this:
Puesdo Code: at start the coins position moves towards random spawnpoints BUT gold coin per spawnpoint
if(there is a cold piece in the spawnpoint) go to another one
if(the coin position and the spawnpoint position are the same) the coin rotates
if(the player comes in contact with the coin) the coins worth (10 points) is added to the player's score score is updated coin object hides
This is what i Have so far: using UnityEngine; using System.Collections; using System.Collections.Generic; using UnityEngine.UI;
public class coinTurns : MonoBehaviour { //ref to the object cion public GameObject coin; //list of the spawnpoints for the coins public List spawnpoints; //ref to the planet public GameObject planet;
// Reference in the inspector UI_Generic.cs that is attached
// to your UIHandler
public UI_Generic myUI_generic;
public ObjRefs obj;
void Start()
{
FlyTowards();
}
void Scatter()
{
for(int i = 0; i < spawnpoints.Count; i++)
{
Instantiate(coin, spawnpoints[i].transform.position, spawnpoints[i].transform.rotation);
}
}
public void FlyTowards()
{
Scatter();
for (int i = 0; i < spawnpoints.Count; i++)
{
foreach (Transform point in spawnpoints)
{
//point = spawnpoints[i].transform.position;
coin.transform.position = Vector3.MoveTowards(coin.transform.position, point.transform.position, 50.0f);
}
}
}
void OnCollisionEnter(Collision collision)
{
if (collision.gameObject == coin)
{
coin.transform.LookAt(planet.transform.position);
Physics.OverlapSphere(planet.transform.position, 300f);
}
if (collision.gameObject == obj.cappyPlayer)
{
obj.Score (10);
obj.UpdateScore();
}
}
void OnCollisionExit(Collision collision)
{
if(collision.gameObject == obj.cappyPlayer)
coin.SetActive(false);
}
void Update ()
{
//rotates the coins
transform.Rotate(transform.right, 50 * Time.deltaTime);
}
}