x


Trouble with turret script

I am trying to finalize a game for school but I'm having a little scripting issue. I get the turret to react to the player when he gets within a pre-determined distance; however my problem is that the turret seems reversed as it's the back that follows the player. Here is the script I am using:

var target : Transform;
var range : float;
var speed : float;

function Update () 
{
    range = Vector3.Distance(target.transform.position, transform.position);
    if (range<200)
    {
        transform.rotation = Quaternion.LookRotation(transform.position - target.position);
    }
    if (range<150)
    {
        transform.Translate(Vector3.forward*speed*2);
    }
}
more ▼

asked Apr 04 '12 at 07:01 PM

Rhys_Pieces gravatar image

Rhys_Pieces
5 3 5 6

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

1 answer: sort voted first
more ▼

answered Apr 04 '12 at 09:57 PM

Owen Reynolds gravatar image

Owen Reynolds
12.2k 1 7 46

(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:

x5273
x982
x173

asked: Apr 04 '12 at 07:01 PM

Seen: 533 times

Last Updated: Apr 04 '12 at 09:57 PM