|
I've got a missile script that uses a few other scripts (like an explosion and MoveObject script), but I can't figure out how to add, access, and use them through this script. Take a look at my code, what do you think I'm doing wrong? p.s. don't question the use of constantforce here, it's just for realism. Condensed Version (the main problem areas--just ask if you want to see the rest) Full Version (comments provide some more detail)
(comments are locked)
|
|
heres my answer that will definitely streamline your code and more than likely fix it. you need to attach all those scripts to the object instead of adding them on runtime. add the projectile gameObject to your project files and instead of having to destroy it you will just reference it every time you spawn a missile. also you could get rid of having a whole other script to move the missile why don't you write one inside of the script that you posted and simply call a function that sets the rigidBodies also to stop the downward movement caused by gravity use rigidbody.UseGravity(false); the reason I haven't put it in project files is because there's 8 individual missile GameObjects and I wanted to put this script on them. but in that case, why don't I just forget about instantiating and just manipulate the GameObjects themselves? facepalm
Aug 14 '12 at 09:24 PM
herp johnson
you could do that haha but instantiate makes a clone so you can have several instances of the same object in the game XD
Aug 14 '12 at 09:26 PM
sman_47o
so what are you trying to do? only allow for eight shots? and I'm right in thinking that this script is inside of the missile object right?
Aug 14 '12 at 09:31 PM
sman_47o
I originally used MoveTowards, but the missile wouldn't actually hit the target, it'd get close and then repel away. I also just now took out transform.LookAt and threw a SmoothLookAt script on the missile GO (game object) for more functionality. Um, yeah, it's just a short educational (but action-packed!) game I'm making, it doesn't have to have over 8 shots and a reload process or anything. it'd be nice though, perhaps I can work on that later. Currently, my objective is to make it so that each time space is pressed, it fires a missile from a different location on the pylon(the thing holding the missiles). I want to get the tracking and explosion down first though.
Aug 14 '12 at 09:42 PM
herp johnson
well if you just instantiate the object you could hit two birds with one stone, make a smoother running game and it will be easier to implement the reload system later.
Aug 14 '12 at 09:46 PM
sman_47o
(comments are locked)
|
|
Ok here's MoveObject. for more info on it go Here enum MoveType {Time, Speed} static var use : MoveObject; Hey im sorry I never got back to you the other day I lost power and I'm currently stealing Internet from my neighbor XD I'll try and get something written from my iPod. But if i can't I can at least point you in the right direction. Use the lookAt function to get your missile (which if i were you id make kinematic so that gravity wont effect it) to look at your target and then set its velocity to transform.forward * speed (speed would be a float that you can fiddle around with to make it do what you want) that's all you really need to move your object. (and if velocity gives you crap, it loves to be difficult, you can also try using translate, add relative force, or position but use velocity if at all possible). Good luck to you and I hope I can some power back soon after they deal with this tree) the world needs educational games with explosives I would have love phonics if I had gotten the reward of demolishing something.
Aug 16 '12 at 12:19 AM
sman_47o
actually I got rid of the instantiation altogether. it was too much trouble. unity reccomends not using velocity so i used Vector3.MoveTowards, which is more dynamic and doesn't screw you over when using colliders. now everything works! :D
Aug 16 '12 at 12:34 AM
herp johnson
Sweet I'm glad you got it going :)
Aug 16 '12 at 01:36 AM
sman_47o
(comments are locked)
|

can we have the rest?
sure thing. i'll put it below the shortened version.
sweet thanks
so what do you think is wrong with it? it's not putting the script on the cloned object, so it must be something with my declarations.
why can't the instantiated prefab already have those scripts attached to begin with? i think you may be making things more complicated than they need to be.