- Home /
Move back to starting point?
I wrote this script, and now I wanna make the object move back where it was when level started on trigger exit, but I don't know how to do that, any help?
var speed : float = 5;
function Update()
{
}
function OnTriggerStay(trig : Collider)
{
rigidbody.isKinematic = false;
if((trig.gameObject.tag == "Player") || (trig.gameObject.tag == "ShipLoaded"))
{
var targ = GameObject.FindWithTag("Player" || "ShipLoaded");
transform.position = Vector3.MoveTowards(transform.position, targ.transform.position, speed * Time.deltaTime);
}
}
function OnTriggerExit(trig : Collider)
{
rigidbody.isKinematic = true;
}
Answer by Sajidfarooq · Sep 06, 2013 at 02:52 PM
You need to store the position on awake/start, then reuse it on OnTriggerExit:
Transform originalPos;
function Start()
{
originalPos = transform.position;
}
function OnTriggerExit(trig : Collider)
{
rigidbody.isKinematic = true;
transform.position = originalPos;
}
Oh how I miss the simple stuff sometimes. xD Yes that's what I want except translate it there but I get it, I just didn't know how to store the coords. Scripting since june and still didn't get the hang of it. xD
Your answer
Follow this Question
Related Questions
How to move an object from point A to point B with one key press 3 Answers
How to lerp back and forth? (ex. platform) 2 Answers
HOW TO MAKE RAGDOLL'S ARMS POINT TO MOUSE AND GRAB WITH CLICK? 0 Answers
How to make moving tiles in side scroller? 1 Answer
Starting a new animation, after stopping another. Without transitions. 1 Answer