Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by DayyanSisson · Aug 18, 2011 at 12:40 AM · spacetrailrenderertrailboost

Boost Streak/Trail

I'm making a space sim, and when the ship activates it's boosters, a trail renderer has to appear and create a trail as it boosts, and when the player turns off boost, the trail renderer disappears. Right now, when the player boosts, in the hierarchy, it says that the trail are there, but visibly, I can't see them on the ship. The trails don't destroy themselves when the boost if off either. Here's the set up

On each wing, an empty game object is there. To the game objects I added the trail script:

var trail : GameObject;

 function Update () 
 {
     if(Input.GetKeyDown ("space")){
 Instantiate(trail, transform.position, transform.rotation);
 }
     if(Input.GetKeyUp ("space")){
 Destroy(transform.trail);
 }
 }

When you hit space, the trail supposedly instantiates (btw, I'm using a trail renderer to make the trail) but nothing happens. Plus, the trail doesn't destroy itself like I wrote in the script. There are no errors, so the syntax is correct. I'm not sure why it's doing this. Help would be appreciated. Thanks in advance.

Update

The questions has almost been answered thankfully to stopsecret but it hasn't been completely answered. Now, using stopsecret's script, I need to make it destroy when you let go of the space bar. I'm not sure how to fix that. Thanks in advance.

Update

I finally figured how to destroy the trail, but the problem is, once the trail is destroyed, you can't instantiate it again, so when I boost, the trail appears, but when I boost again the trail isn't there. So I need to figure out a way to destroy the trail when not boosting, and have it continually come up whenever I boost. Here's the script:

 var trail : GameObject;
 
 function Update ()
 
 {
 
 if(Input.GetKeyDown ("space")){
 
 var trailTransform = Instantiate(trail, transform.position, transform.rotation);
 
 trailTransform.transform.parent = transform;
 
 }
 if(Input.GetKeyUp ("space")){
 
 Destroy(gameObject);
 
 }
 In the script, once the gameObject is destroyed, it doesn't instantiate again. How would I solve this?
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

6 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by kilgore · Aug 18, 2011 at 12:52 AM

It looks like you need to parent the instantiated trail object to the ship. Can you check to see if it is being instantiated at zero coords?

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image DayyanSisson · Aug 18, 2011 at 01:17 AM 0
Share

Well, the gameobject that has the trail script on it is a parent, but you're right, the trail is not a parent. I have no idea how to make the trail a parent.

avatar image
0

Answer by stopsecret · Aug 18, 2011 at 01:34 AM

to make the trail a parent, here's what you do: ok, so before Instantiate, type a variable you want like trailTransform, then put an equals sign. Now this makes trailTransform a variable, and it can be accessed like a regular object. You can from there type trailTransform.parent = transform in order to parent the trail to your empty object. Finished code looks like this:

trailTransform = Instantiate(trail, transform.position, transform.rotation);

trailTransform.parent = transform

I hope this works, good luck on your space game endeavor!

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image DayyanSisson · Aug 18, 2011 at 01:43 AM 0
Share

I did that. It doesn't work. Here's the script:

 var trail : GameObject;
 function Update () 
 {
     if(Input.Get$$anonymous$$eyDown ("space")){
 var trailTransform = Instantiate(trail, transform.position, transform.rotation);
 
 trailTransform.parent = transform;
 
 }
     if(Input.Get$$anonymous$$eyUp ("space")){
 Destroy(transform.trail);
 }
 }

What did I do wrong?

avatar image
0

Answer by stopsecret · Aug 18, 2011 at 01:48 AM

I think what you did wrong was put var in front of trailTransform, try without it...

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image DayyanSisson · Aug 18, 2011 at 01:50 AM 0
Share

nope, stil doesn't work

avatar image
0

Answer by stopsecret · Aug 18, 2011 at 01:59 AM

ok, I have taken your script into unity and tested it out. After fixing the errors, here's what i've come up with. I couldn't get rid of the trail after I was done, but I think you can figure that out... problem was I called trailTransform's gameObject, which i don't think has a parent function. A quick conversion to transform, and you're all set!

var trail : GameObject;

function Update ()

{

 if(Input.GetKeyDown ("space")){
 
 var trailTransform = Instantiate(trail, transform.position, transform.rotation);

 trailTransform.transform.parent = transform;

 }
 if(Input.GetKeyUp ("space")){
 
 Destroy(transform.trail);
 
 }

}

Hope this one actually works ;)

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image DayyanSisson · Aug 18, 2011 at 02:04 AM 0
Share

Perfect man! This works. Thanks a lot. (Now I just have to figure out how to destroy it :(

avatar image
0

Answer by Peppercat · Aug 27, 2013 at 09:28 PM

In answer to your second update, why don't you put your "trail" object in Resources folder? Then you can instantiate it as a prefab, and consequently instantiate and destroy it all the times you need to. That worked for me, hope it helps!

To create it:

 GameObject trail = Instantiate(Resources.Load("TrailPrefab") as GameObject, gameObject.transform.position, Quaternion.identity) as GameObject;
 trail.transform.parent = gameObject.transform;
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
  • 1
  • 2
  • ›

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Is possible to save a trail rendered to load again after? 1 Answer

How to Change Trail Render Position in 3D? 1 Answer

Shadow's aren't showing on my trail, "I have "Receive Shadows" checked,My trail isn't receiving shadows, I have "Receive Shadows" checked 0 Answers

How to make trail renderer working with the URP ? 0 Answers

Trail behind standing player 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges