- Home /
Simple Script Problem
Hello, i would like this script to follow the rotation of the Target, just not only the position. What do i need to add? Also it needs to only rotate on 2 axis only.
using UnityEngine;
using System.Collections;
public class CamerFollow2 : MonoBehaviour {
public Transform Target;
void LateUpdate ()
{
transform.position = new Vector3(Target.position.x, transform.position.y, Target.position.z);
}
}
Answer by Mr.Z · Jan 04, 2013 at 10:43 PM
Check this out: http://docs.unity3d.com/Documentation/ScriptReference/Transform.Rotate.html
As the documentation says, the parameters are: Rotate (xAngle : float, yAngle : float, zAngle : float, relativeTo : Space = Space.Self). If you do not want to rotate in a specific angle, just set the parameter to 0.
using UnityEngine;
using System.Collections;
public class CamerFollow2 : MonoBehaviour {
public Transform Target;
void LateUpdate ()
{
transform.position = new Vector3(Target.position.x, transform.position.y, Target.position.z);
transform.rotate = (Target.eulerAngles.x, Target.eulerAngles.y, Target.eulerAngles.z); //I belive? not too sure tbh
}
}
yes but how would i add it in my script, so it follows the Targets Rotation? Like Look-at.
so would it be transform.rotate = (transform.rotate.x, Target.rotate.y, Target.rotate.z);
What will you rotate to when "so called stalker" is allways inside the target..
Your answer
Follow this Question
Related Questions
LookAt Translation Not Sticking 1 Answer
Lock rotation axis? 4 Answers
Joint Transform Rotation in Unity? 0 Answers
transform.LookAt issue 1 Answer
How do I get GameObjects to look at me? 2 Answers