Skip to content

Instantiate Projectile

User created LBs

Instantiate Projectile

Postby Viziopleasure » 20 Apr 2011, 16:45

Ok, lunchtime so I've done this, maybe of some help:

Image

Owner is the GameObject(Transform) your projectile spawns from.
Original is the GameObject you want to instantiate.
Projectile Speed its what it says, controls the speed of your projectile(forward).
Ignore Owner's Collider let your projectile ignore collision with the object it spawns from, good for guns.

Just create a C# script and replace its content with this:
Syntax:
Using csharp Syntax Highlighting
/*
 Bruno Xavier L' - 20 April 2011
 Use this as you wish and on your own risk
 File is granted as 'is' and published under General Public License
*/


using UnityEngine;
using Antares.Vizio.Runtime;

[VisualLogicBlockDescription("Instantiate Projectile")]
[VisualLogicBlock("Projectile", "Instantiate")]
public class OGSInstanceProjectile : LogicBlock {

        [Parameter(VariableType.In, typeof(Transform), Name = "Owner")]
        public Variable inOwner;

        [Parameter(VariableType.In, typeof(Rigidbody), Name = "Original")]
        public Variable inObject;

        [Parameter(VariableType.Out, typeof(Rigidbody), Name = "Original")]
        public Variable outObject;

        [Parameter(VariableType.Out, typeof(Rigidbody), Name = "Instance")]
        public Variable outInstance;

        [Parameter(VariableType.In, typeof(float), Name = "Projectile Speed")]
        public Variable inSpeed;

        [Parameter(VariableType.Out, typeof(float), Name = "Projectile Speed")]
        public Variable outSpeed;

        [Parameter(VariableType.In, typeof(bool), Name = "Ignore Owner's Collider")]
        public Variable inIgnore;
       
        //

        public override void OnInitializeDefaultData() {
                RegisterOutputTrigger("Success");
                RegisterOutputTrigger("Failure");
        }
       
        //

        [EntryTrigger]
        public void Begin() {
                if (inObject.Value != null) {
                        Transform owner = (Transform)inOwner.Value;
                        Rigidbody instantiatedProjectile = (Rigidbody)Object.Instantiate((Rigidbody)inObject.Value,owner.position,owner.rotation);
                        instantiatedProjectile.velocity = instantiatedProjectile.transform.TransformDirection(new Vector3(0,0,(float)inSpeed.Value));
                        if (inIgnore.showInInspector && (bool)inIgnore.Value == true) {Physics.IgnoreCollision(instantiatedProjectile.collider,owner.collider);}
                        //
                        outInstance.Value = instantiatedProjectile;
                        outObject.Value = inObject.Value;
                        //
                        ActivateTrigger("Success");
                } else {
                        Debug.LogWarning(this.ToString()+": Original Object null? Please, check out 'Parametres IN'");
                        ActivateTrigger("Failure");
                }
        }

}
 
Parsed in 0.016 seconds, using GeSHi 1.0.8.4


A Smart Block will appear in Universe, Smart Blocks > Instantiate > Projectile. Have fun.
User avatar
Viziopleasure
 
Posts: 115
Joined: 31 Mar 2011, 12:08

Re: Instantiate Projectile

Postby Visionaries 777 » 27 Apr 2011, 03:48

It's really nice, good job! However, it could be great if the instantiated objects could get destroyed by themselves after some time for example. Also, would it be possible to choose the direction of projection, and maybe its speed?
User avatar
Visionaries 777
 
Posts: 50
Joined: 29 Mar 2011, 07:15
Location: Hong Kong

Re: Instantiate Projectile

Postby Viziopleasure » 27 Apr 2011, 04:05

Yeah, the speed you can manipulate already.
The other parameters you would just to use as one more input parameter, like the existing ones. Its not a hard task.

Self-destruction must be a script/graph attached to the prefab instanciated. The easier and practical way I think.
User avatar
Viziopleasure
 
Posts: 115
Joined: 31 Mar 2011, 12:08

Re: Instantiate Projectile

Postby Kamilla1 » 24 Nov 2015, 14:13

Nice post helps me alot thanks.
Kamilla1
 
Posts: 11
Joined: 24 Nov 2015, 13:11


Return to Smart Blocks

Who is online

Registered users: No registered users