Hi again peeps. Quick question: How do I find and record into a floating variable the position of a moving object?
Here’s my JS code:
var gel : Transform;
var on = false;
var speed : float = -20;
var chDir = false;
var release = false;
var start = true;
function OnTriggerEnter (pipCollider)
{
if(pipCollider.gameObject.name == "Pip")
{
on = true;
}
}
function Update()
{
if(start)
{
gel.transform.Translate(Vector3(0,speed,0) * Time.deltaTime);
}
if(on)
{
start = false;
var pivot = pip.position;
gel.transform.RotateAround (pivot, Vector3.forward, 50 * Time.deltaTime);
chDir = true;
}
else if (!on){}
if(chDir && Input.GetButtonDown("Fire1"))
{
on = false;
release = true;
}
if(release)
{
var pivotor = pip.position;
var orbitor = gel.position; //here lies the problem - we want a snapshot of the gel position not the uptodate one
var vect = (orbitor-pivotor).normalized;
var newSpeed = speed*vect;
gel.transform.Translate(newSpeed * Time.deltaTime);
}
}
In the if(release) statement, the orbitor variable is set to the position of the gel Transform object. However, this variable changes over time and I want the orbitor to remain a fixed snapshot of the gel position at the moment the mouse is clicked.
For clarity: I want to put snapshot values into the orbitor variable that do not change after the object has moved. I also want to be able to swap that value for another snapshot later on.
Any thoughts?