x


Why can't I set the Target

I'm trying to set the target of a homing shot after it's spawned when an enemy is hit by ray cast, but it doesn't work and I can't figure out why. It's suppose to set the enemy who's been placed into an Array.

var SLT: Array = new Array();
var Homing: GameObject;
var current: int = 0;

var slShot: GameObject = Instantiate(Homing, transform.position, Quaternion.identity);
slShot.transform.GetComponent("Projectile").Target = SLT[current].transform;
slShot.rigidbody.AddForce(transform.forward * 10, ForceMode.Impulse);

Here's the Projectile's script:

static var Target: Transform;

function Update(){


transform.LookAt(Target);
transform.position = Vector3.Lerp(transform.position, Target.position, Time.deltaTime * 10);
Destroy(gameObject, 3);
}
more ▼

asked Dec 13 '11 at 06:09 PM

Persona gravatar image

Persona
246 74 85 96

(comments are locked)
10|3000 characters needed characters left

1 answer: sort oldest

Since your Target is a Static var, you do not need to set it in the specific script. You can just do

Target = SLT[current].transform

Tell if it's of any help.

more ▼

answered Dec 13 '11 at 06:17 PM

Oninji gravatar image

Oninji
332 43 47 50

No change.

Dec 16 '11 at 09:02 PM Persona

Can you describe me the current behavior of the bullet?

Dec 16 '11 at 11:42 PM Oninji

The bullets spawn, but they don't move. The rigidbody's force isn't being applied and the target isn't being set.

Dec 17 '11 at 12:22 AM Persona
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x355
x243
x20
x19

asked: Dec 13 '11 at 06:09 PM

Seen: 492 times

Last Updated: Dec 17 '11 at 12:22 AM