- Home /
Create a Proximity Mine
I'm making a 2D game where the player has to collect green orbs while dodging grey orbs. I want to make proximity mines, where if the player gets too close they will explode and 6 grey orbs will fire out in all directions.
I've got the proximity part set up and working with this script:
var targetObj : GameObject; var proximity : float = 3;
function Update() {
var dist = Vector3.Distance(targetObj.transform.position, transform.position);
if (dist < proximity) { Destroy(targetObj); } }
I just don't know how to get it to create 6 grey orbs after the mine object is destroyed and have them shoot out. I know it has to do with Instantiate, but I couldn't get it to work correctly. Any help would be greatly appreciated.
Answer by Loius · Oct 23, 2010 at 08:25 PM
If the orbs are triggers, this should work-
var orb : GameObject = Instantiate( orbPrefab, transform.position, Random.rotation );
orb.rigidbody.velocity = Random.insideUnitSphere.normalized * orbSpeedMultiplier;
If they are not, they'll need to be spaced out when instantiated or they'll interfere with each other. Colliders inside one another makes wonky physics.
Your answer
Follow this Question
Related Questions
Reading XML file 0 Answers
How to insert an object after Destroy(gameObject) 2 Answers
Instantiated Objects not being set at ground/terrain level?(Solved) 1 Answer
How to correctly convert Object to GameObject 1 Answer
Checking Instantiate/Destroy has been called | Checking number of scene GameObjects 1 Answer