- Home /
Question by
autumn_737 · Mar 18, 2012 at 04:57 AM ·
translationdestination
Changing destination on a move object script
Hi, I'm trying to make a code that puts one object from one position to another, I have this code but I cannot change the end destination to my liking and I'm struggling to understand it. Any help would be appreciated. :)
enum MoveType {Time, Speed}
static var use : MoveObject;
function Awake () {
if (use) {
Debug.LogWarning("one only");
return;
}
use = this;
}
// translates an object's position to another
function Translation (thisTransform : Transform, endPos : Vector3, value : float, moveType : MoveType) {
yield Translation (thisTransform, thisTransform.position, thisTransform.position + endPos, value, moveType);
}
// smoothly moves and object from a point to another
function Translation (thisTransform : Transform, startPos : Vector3, endPos : Vector3, value : float, moveType : MoveType) {
var rate = (moveType == MoveType.Time)? 1.0/value : 1.0/Vector3.Distance(startPos, endPos) * value;
var t = 0.0;
while (t < 1.0) {
t += Time.deltaTime * rate;
thisTransform.position = Vector3.Lerp(startPos, endPos, t);
yield;
}
}
// rotates to a certain limit given speed and time values
function Rotation (thisTransform : Transform, degrees : Vector3, time : float) {
var startRotation = thisTransform.rotation;
var endRotation = thisTransform.rotation * Quaternion.Euler(degrees);
var rate = 1.0/time;
var t = 0.0;
while (t < 1.0) {
t += Time.deltaTime * rate;
thisTransform.rotation = Quaternion.Slerp(startRotation, endRotation, t);
yield;
}
}
thanks for your time.
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613065237im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Changing destination on a move object script 1 Answer
Vector-based movement? 1 Answer
JS to C# Translation? 2 Answers
Having a problem translating part of a script which uses C# delegates into JS 0 Answers
Unable to cast from the source? 1 Answer