- Home /
How can I get it from point b to point c
I have a sphere, right now I have it traveling to the position of a cube. how do I get it to travel to the position of another cube only after hitting the first one? here's my script.
var start : Transform; var end : Transform;
function Update () {
transform.position = Vector3.Lerp (transform.position,end.position,Time.time);
}
I'm assuming I would be using an if state, maybe something like: If(GameObject is here) {move it here}
That's just an un-educated guess though.
UPDATE**
Okay I made a collision script, and though I get no errors it doesn't seam to do anything. My objects have rigid bodies but no colliders, here's the script.
var start : Transform; var end : Transform; var end2 : Transform;
function Update () { transform.position = Vector3.Lerp (transform.position,end.position,Time.time);
}
function OnCollisionEnter(collision : Collision) { if(collision.gameObject.name == "hit") transform.position = Vector3.Lerp (transform.position, end2.position,Time.time);
}
Answer by Lance · Nov 21, 2010 at 12:33 AM
Try Lerping from the "start" position you set up instead of the transform.position you have in code now.
Update
Apologies. I think I know what you mean now, you're wanting to queue the action of movement. Unless you have some other system determining your "next" position, I would think the easiest way would be to have a script that checks for the moving object to collide with it, then has a moveTo property (Vector3 or GameObject) assigned to it that indicates where to move next. Then place a movement script on the moving object to check against whether your current position is where you're supposed to be; if not, Lerp to it.
Yeah, a collision detection script crossed my $$anonymous$$d. However I'm doing this sphere cube stuff because I'm trying to learn all I can about vector3 and translation at the moment, so I wanted to try to do it using that kinda stuff.
Answer by Uriel_96 · Nov 21, 2010 at 12:33 AM
try this script:
transform.localPosition.x = other.localPosition.x;
or you also can use this one if you want the entire object:
transform.position = other.position;
and if you want to do it for some time you use Time.deltaTime * speed;
Sorry, I'm a bit of a slow learner. Are you saying use that script in an if statement, like "If(transform.localPosition.x = other.localPosition.x;)
??
No, the localPosition has his name says is to the position the object you have to get to a position, so its just say to the object position gets to the other object and use the Time.deltaTime to go in a specific time to the object and its the same with the transform.position(use the position is better than use the localPosition)
Your answer
Follow this Question
Related Questions
What is wrong with my zipline script? 2 Answers
Why does this placement script not work? 1 Answer
fixed distance for Vector3.moveTowards ? 1 Answer
Vector3 Projection 2 Answers
Vector3 Transform.Position Not Working 2 Answers