- Home /
C# Probability of Transform Colliding
Hi. I am trying to make two scripts. One below that is attached to an asteroid and moves it towards the target planet, and a second one to place on an observatory that would find the probability of the asteroid colliding with the target.
I know the script I have so far is completely wrong as the asteroid will always collide with the target every time. What I'm trying to do is get it to have a random probability of reaching the target and a second script that would calculate that probability. I am completely stuck and help to point me in the right direction would be much appreciated!!!
using UnityEngine;
using System.Collections;
public class Asteroid : MonoBehaviour {
public Transform target;
//Planet
public float speed;
//Speed of Asteroid
void Update() {
float step = speed * Time.deltaTime;
transform.position = Vector3.MoveTowards(transform.position, target.position, step);
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Planet") {
print ("Asteroid Impact");
Destroy (gameObject);
//Destroys Asteroid
}
}
}
Answer by mar10 · Jun 18, 2016 at 05:44 AM
@Vuzok try adding a coroutine that gives you two random numbers 0 & 1, set the coroutine to wait in seconds so you have control over the intervals. now every time the number is 0 make the asteroid hit the target if it is 1 make it miss the target.
Sorry for the late reply. That's a good idea thanks for pointing me in the right direction!