- Home /
Rotation of my enemy How??
Hi....
I have an enemy that goes from PointA to PointB and then from PointB to PointA....
Here is the script..
var pointB : Vector3;
function Start () { var pointA = transform.position; while (true) { yield MoveObject(transform, pointA, pointB, 3.0); yield MoveObject(transform, pointB, pointA, 3.0); } }
function MoveObject (thisTransform : Transform, startPos : Vector3, endPos : Vector3, time : float) { var i = 0.0; var rate = 1.0/time; while (i < 1.0) { i += Time.deltaTime * rate; thisTransform.position = Vector3.Lerp(startPos, endPos, i); yield; } }
I am new to unity and i need a little help... I want when my enemy goes to PointB to rotate 180 and go back to pointA...but i dont know how to do it...Thank you.
Answer by JesusChristChangedMe · Nov 15, 2010 at 10:24 PM
here is what you need, just adding transform.rotate to the script and rotating it across the y axis to turn it around.you had almost exactly right.
but here it is
var pointB : Vector3;
function Start () {
var pointA = transform.position;
while (true) {
yield MoveObject(transform, pointA, pointB, 3.0);
transform.Rotate(0,180,0);
yield MoveObject(transform, pointB, pointA, 3.0);
transform.Rotate(0,180,0);}}
function MoveObject (thisTransform : Transform, startPos : Vector3, endPos : Vector3, time : float) {
var i = 0.0;
var rate = 1.0/time;
while (i < 1.0) {
i += Time.deltaTime * rate;
thisTransform.position = Vector3.Lerp(startPos, endPos, i);
yield; }}
hope this is what you need!
Answer by Antonios · Nov 16, 2010 at 12:59 PM
When adding the
Transform
Make sure that the (x, y, z) is correctly set up. Other wise, try using
Transform(x, Quaternion, z)
Quaternion is only used to define new rotaions to something that already defines a rotaion. Thus you almost never access or change individual Quaternion's (x,y,z,w); most often you would just take existing rotations (e.g. from the Transform) and use them to make new rotations. but Transform(x, Quaternion, z) wont do any good because Quaternion isnt used that way. it would be something like transform.Rotaion(x,y,z); just to clarify. :)