x


Define var target : Transform; within the script

I'm trying to predefine the var target : Transform; object within the script for use on a instantiated prefab.

var target : Transform;
var damping = 6.0;
var smooth = true;

@script AddComponentMenu("Camera-Control/Smooth Look At")

function LateUpdate () 
{
    if (target) 
    {

        if (smooth)
        {
            // Look at and dampen the rotation
            var rotation = Quaternion.LookRotation(target.position - transform.position);
            transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping);
        }
        else
        {
            // Just lookat
            transform.LookAt(target);
        }
    }
}

function Start () {
    // Make the rigid body not change rotation
    if (rigidbody)
        rigidbody.freezeRotation = true;
}
more ▼

asked Feb 16 '11 at 04:06 PM

Caiuse gravatar image

Caiuse
787 83 103 121

Why not set target in Start()? Best I could offer given how little explanation you've given.

Feb 16 '11 at 04:11 PM PrimeDerektive

What's not working?

Feb 16 '11 at 05:01 PM yoyo
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

I think i explained myself wrong but anyway, I was trying to define a target using a tag, so i had to add the following to the LookAt script.

var player : GameObject;
player = GameObject.FindWithTag("Player");
transform.LookAt(player.transform);

http://forum.unity3d.com/threads/78332-Using-LookAt()-with-tags

Thanks

more ▼

answered Feb 16 '11 at 09:51 PM

Caiuse gravatar image

Caiuse
787 83 103 121

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

x5070
x3455
x329
x207

asked: Feb 16 '11 at 04:06 PM

Seen: 2411 times

Last Updated: Feb 16 '11 at 04:06 PM