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!

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? More information will definitely help.

Nice formatting! :)

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

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.

That's what I thought as well, but when I launch the Missile object without the Explosion GameObject in the Explosion variable (in the Projectile script [in inspector]), it launches fine.

2 Answers

2

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.

I'm sorry to tell you that I never got anywhere with that. I don't even remember what project this was for. But I would suspect you could do something like getting the next waypoint's position and then making it look in that direction, if that is to any help.

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.

Also are you getting any errors by any chance?