- Home /
Space Torpedo
What would be the best way to go about making a space torpedo like in trek films? I would also think there's some kind of orb effect built in to unity that I can use? Any who I am all ears… any help is great, even documentation is fine. Been using C# as its like c++.
Answer by xt-xylophone · Nov 01, 2013 at 12:57 AM
You havn't given much on what features you want but ill tell you some structure to aim for to get started.
First make an empty gameobject, called Torpedo or w/e you want. Put its coordinates and rotation all to ZERO so you can orient it correctly.
Now create the effects you want, look at some tutorials on particles or models and put it as the child of the blank gameobject. This means the graphic and the object itself are separate and become much easier to change. Make sure this is at zero too. Also make sure its facing the Z axis because in your script you'll probably use transform.forward to make movement and forward is the Z axis.
Add a script to the parent object called Torpedo (once again w/e you want). The simplest kind of torpedo goes straight. So make a public float variable called speed. In the Update function do something like this:
transform.Translate(transform.forward * Time.deltaTime * speed);
This means the torpedo will move forward at speed/second. Since it was public you can edit in the Unity editor now :) If you want more advanced movement, edit how it moves here!
Drag this object into the folders window and it becomes a prefab. Look up how the Instantiate function works and in another script use that to create the missile at the point you want. Once its made it will fly straight at that speed.
But this will just go through walls and stuff. Add a collider to the parent, make a close shape to what you need, simpler the better then look up OnCollisionEnter(http://docs.unity3d.com/Documentation/ScriptReference/Collider.OnCollisionEnter.html)
This function gets called when the collider hits stuff so do whatever you need in that function, maybe checks to see what it hit and do accordingly.
This is the most basic way to make a torpedo/missile/bullet I can think of. Try this and play around, you'll pick up and understand what you need to do next to make something cool :)
Good luck!
That was pretty much a guideline on what to do when you already know how to use Unity. Im guessing you're pretty new? Thats cool but you havn't given much info on what you actually want. Just a torpedo? Want it to move? Just the graphic? What created the torpedo? Theres a thousand more questions I can ask so you need to be more specific. Id recommend doing some basic scripting tutorials and once you've done them reread my post and you should have an idea of what you should do to do whatever you want.
Well you are right very new but I have experience in c++ so c# is no big deal just the unity specific code is challenging but I think I got it covered. I am looking to make a empty object attached to my ship that launches a torpedo at the selected target(have existing script that does that from my beam weapon) it hits the enemy ship and causes damage then disappears. How to make graphic is big concern in the process, I have only worked will models in unity not particles and stuff. I will most likely make a gui button that launches the torpedo.The link shows an idea of what it looks like… behind the green ship is the torpedo flying at ship Click here
Ah I see so you're getting quite far into it :D
For the torpedo they look like a very bright light with a short trail. What you could do:
Have empty Gameobject as the root of the torpedo
Add a box/sphere collider to it to the right size
$$anonymous$$ake 2 fire prefabs(The basic one that comes in the standard assets package) and add them as the child of the torpedo.
Find the checkbox for world/local space and check it for ONE of them. This means that one will make a trail as it moves and the other will just form a ball since it render in its own local space.
Edit all the values to get a feel for what they do until you have the desired look.
$$anonymous$$aybe add a light source component to the parent, maybe even with a lense flare on it.
Play around with it, theres a couple tuts on particles so im sure you could make something look pretty cool!
Your answer
![](https://koobas.hobune.stream/wayback/20220613120958im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Rotation Speed 1 Answer
Distribute terrain in zones 3 Answers