Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Soozle · Nov 25, 2013 at 07:30 PM · collisionfpsnewbiefpstutorial

Missile launcher is malfunctioning

Hello,

I am working through the old FPS Tutorial, and everything has been going smoothly up until this point. I have managed to create a launcher that launches the "Missile" GameObject, which is a grey sphere. My problem arose when the time came to assign a GameObject to the "Explosion" variable in the "Projectile" script (Projectile.js was a component of Missile.prefab).

Basically, this is what happens: I fire with Left-click (Fire1) and it simply spawns an explosion at my character (the capsule). It SHOULD be launching the sphere and then exploding upon collision with other objects.

I can provide code if it helps, but I am stuck at this point and do not know what to do.

Thank you!

Comment
Add comment · Show 8
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 iwaldrop · Nov 25, 2013 at 07:51 PM 0
Share

In general, yes, post code when asking code questions.

Is it possible that your missile is colliding with the player or the launcher? Or that your explosion effect is active already and thus explodes as soon as it is spawned? $$anonymous$$ore information will definitely help.

avatar image Soozle · Nov 25, 2013 at 08:10 PM 0
Share

Okay, here is the code.

Projectile.js

 var explosion : GameObject;
  
 function OnCollisionEnter( collision : Collision )
 {
 var contact : ContactPoint = collision.contacts[0];
 var rotation = Quaternion.FromToRotation( Vector3.up, contact.normal );
 var instantiatedExplosion : GameObject = Instantiate(
 explosion, contact.point, rotation );
 Destroy( gameObject );
 }



Code for Explosion.js

 var explosionTime = 1.0;
 function Start()
 {
 Destroy( gameObject, explosionTime );
 }



Code for $$anonymous$$issileLauncher.js

 var projectile : Rigidbody;
 var speed = 20;
 
 function Update()
 {
     if(Input.GetButtonDown("Fire1"))
     {
         var instantiatedProjectile : Rigidbody = Instantiate(
             projectile, transform.position, transform.rotation );
         instantiatedProjectile.velocity = 
             transform.TransformDirection( Vector3( 0, 0, speed ) );
         Physics.IgnoreCollision( instantiatedProjectile. collider, 
             transform.root.collider );
             
     }
 }


avatar image iwaldrop · Nov 25, 2013 at 08:11 PM 1
Share

Nice formatting! :)

avatar image Soozle · Nov 25, 2013 at 08:33 PM 0
Share

The commenting section messed up my layout. Anyways, do you know how I can resolve this issue? You mentioned something about it beco$$anonymous$$g active and exploding immediately, so is there a way for it to become active upon collision?

avatar image iwaldrop · Nov 25, 2013 at 09:34 PM 0
Share

If you look at the code, when OnCollisionEnter is called on the Projectile the explosion gets instantiated. As I suspected, your missile is likely colliding with something as you're firing it.

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Soozle · Nov 25, 2013 at 09:44 PM

Ah, I fixed it! All I had to do was move the Launcher object further away from the Capsule so it didn't collide. Thanks for the assistance! Please close.

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
avatar image
0

Answer by Commander Quackers · Nov 26, 2013 at 03:21 AM

I suspect that your missile is colliding with the launcher or the player. In order to make this work, you should make it so that the projectile is not colliding or on a path of collision with the launcher/player. For instance, if the projectile is colliding with the launcher or player as it spawns, it will make it explode near you. If it wasn't colliding, it would wait for a collision (wherever it's being fired to) to explode.

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 Commander Quackers · Nov 26, 2013 at 03:05 AM 0
Share

Also are you getting any errors by any chance?

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

19 People are following this question.

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

Related Questions

Multiple Cars not working 1 Answer

Particles are off when I shoot 1 Answer

Enemy Collision Wont Work! PLEASE HELP 0 Answers

how to morph character on collision enter with gameobject 1 Answer

Enemy deals damage to player on contact 2 Answers


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