|
Hello, I have this turret that fires homing missiles (well, supposed to anyway). This is how I have my set up: On the turret parent, I have a script called MissileControl, in a child of that I have another script called SmoothLookAt. The SmoothLookAt rotates the turret to face an enemy that steps into the radius and adds their transform to a generic list. The MissileControl reads the enemy from the SmoothLookAt list and add it to its own variable (so it doesn't change if a new enemy steps in the radius) - and fires missiles (projectile). This is where it starts to go funny: In the script that controls the projectile itself (called: Projectile) needs to follow the enemy that MissileControl has added ... but it doesn't. This is because it fails to receive the target from MissileControl. So the target is sent downwards: SmoothLookAt > MissileControl > Projectile (which is initiated): SmoothLookAt: (Snippet)
MissileControl:
Projectile:
I have been stuck on this for ages!! All that happens is that the missiles just fire in a straight line - and does not track the enemy at all. I think its something to do with the sendmessage - as I need to tell the projectile the enemies transform ... Where am I going wrong?
(comments are locked)
|
|
You have a lot of really strange code fragments xD, but your (main) problem is in Start() of your projectile. You use GetComponent(MissileControl) on the projectile!!! I guess the projectile don't have a MissileControl, your launcher object have that script. You should do it the other way round. You always said you passing the target to your projectile but it's reverse. The projectile tries to find the MissileControl. Just do this in your MissileControl script:
Now you pass the target TO the projectile. I'll assumed that "Projectile" is your script name. ( Now i'll go to bed can't see much more of this "dirty language". C# is the way to go ;D )
(comments are locked)
|
|
Make sure that the target is actually set in Projectile's start (use debugger or Debug.Log). In LateUpdate, I'd look into using Lerp or Slerp or MoveToward or something along those lines. Its not in the projectile - Thats what I'm trying to solve, it will be fine when I get the target added to the projectile, but it doesn't add its self.
Jan 26 '11 at 01:40 PM
oliver-jones
How would I go about doing that? My projectile works fine when it has a target ... but it fails to receive target from MissileControl
Jan 27 '11 at 03:02 AM
oliver-jones
closeObjects is getting updated somewhere, correct (code not shown)? Such that there is an enemy to track? Because if not, SmoothLookAt.target won't be set (to anything valid), and that is what becomes MissileTarget, right? I'd get into the debugger and/or start peppering code with Debug.Log's to make sure that things are in fact happening as you intend them to. Make sure a target gets set and is available.
Jan 28 '11 at 01:08 AM
DaveA
closeObjects is in the SmoothLookAt - which is places an enemy in a target variable - MissileControl then reads the target from SmoothLookAt and places it into its own variable (this bit works) - what fails is for MissileControl to pass on the target to the projectile. (I cant be static by the way)
Jan 28 '11 at 01:50 AM
oliver-jones
(comments are locked)
|
|
I dont really have time to look at it really hard right now.. But you can try this. Instead of passing the target variable down. Try in the start function for each projectile do a gameObject.FindWithTag(theLauncherTag)... It might work.. Worth a shot ;-) What do you mean by 'theLauncherTag'? - you mean, like use the enemy tag for the projectile to find it? That does work, yes - but thats not what I want - I want to the missile (projectile) to follow a specific enemy (target - that is placed in the generic list) ... If I use enemy tags - then all the missiles will follow the first enemy initiated.
Jan 28 '11 at 02:58 AM
oliver-jones
No, I mean have the launcher have that tag.. Then once you have the launcher then you can get and use the target variable... And BTW, thelauncherTag was just meant to just be a placeholder... It will give a error.
Jan 28 '11 at 03:09 AM
3dDude
(comments are locked)
|

Basically: I somehow need to tell my Projectile the enemy transform from MissileControl