- Home /
How can i attach a bullet to a tower
i can put several towers in the scene, and they shoot when they are seeing an enemy, my problem is that i have a Checker script in my tower (where i check distance with enemies)and i want to make the bullet follow the enemy that the FOR gaves me. I know that i have to attach my tower to a public gameobject in the bullet so i can Get the component Checker but i cant. the steps are: 1) create tower 2) detect enemy distance - save the enemy index in Checker 3) shoot 4) the bullet following the enemy with the Index saved
Thx!
Either I'm even more tired than I already think I am, or ...somethin...
You wanting a heat-seeking bullet of a sort, or what?
Edit:
I'm bored, half asleep, and been staring at my computer screen for round-about 12 hours now. Just felt like adding to this comment that my initial thought when I first saw the title of this question was "Duct Tape".
Are you instantiating the bullet every time, or enabling/disabling it?
If you're instantiating it, you can set the target when instantiating.
Then just lerp between positions.
Answer by haider1515 · Dec 13, 2011 at 04:07 PM
Instantiate the bullet at the tower.position+offset.. define rang say range=5; gameobject target=findtagwith(enemy); if(vector.distance(transform.position,target.postion)
GameObject.LookAt.... give it a tag which you want to follow.. bullet.lookat ( target)..forceon forward
Select your code and hit ctrl+$$anonymous$$ or click the Code Sample button (the icon with binary on it) to format your code and make it readable please.
Answer by Martin_Gonzalez · Dec 14, 2011 at 01:55 AM
I finish using raycast, is not wat i expected, but it works well. Thx everybody!
Your answer
Follow this Question
Related Questions
Get number from a variable name 0 Answers
Having Trouble with this For Loop 1 Answer
For loop going based off of Time.deltatime? 1 Answer
Stopping A Loop - Return or Break? 2 Answers