- Home /
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.
Answer by ByteSheep · Mar 18, 2012 at 04:13 AM
After a quick glance it looks like endPos is the Vector3 variable that you need to change to set a different end destination.. Your question is a bit unclear - have you been able to change the end position but just not to the correct position, or are you having trouble change it's value altogether?
I gathered that end pos was somewhat the destination points, I just don't know how to re enter the points to put in a new target.
Sorry I couldn't make it clearer. So I want to put in 'object_des' where the end pos variable to make it read that information ins$$anonymous$$d. :)
You could try just setting
endPos = object_des;
That way the endPos variable will be set to the same destination as object_des..
Your answer
Follow this Question
Related Questions
Changing destination on a move object script 0 Answers
Objects Going to 0, 0, 0 Coordinates 3 Answers
Camera at wrong place after build 1 Answer