- Home /
tranform position
how do you get the last known tranform position of an object. then set it to that position
Answer by mcroswell · Mar 05, 2010 at 11:24 PM
In JavaScript you would make a variable that will "stick around" in-between updates. Then, you can set it to that whenever you want (meaning it won't move any more).
So, something like this might be what you want? Be aware, the following code was not tested but just typed-in here (expect missing semi-colons, etc):
----------somescript.js------------
private var lastPosition : Vector3; // The last position.
public var bStayPut: boolean; // Public so you can change it while running in editor.
// Initialize in Start (or Awake):
function Start() { lastPosition = transform.localPosition; }
function Update() { if (bStayPut) transform.localPosition = lastPosition; // Stay put. else { transform.localPosition.x += .01; // Move to the right, or whatever you want. lastPosition = transform.localPosition; } }
Your answer
Follow this Question
Related Questions
Create a straight gradient equation with a grid of 3d objects 1 Answer
How do I freeze a gameObject when MouseDrag runs over a certain Vector3? 1 Answer
Create an animation with variables? 1 Answer
not instantiating at correct transform 2 Answers
Object not moving,Object not moving in any direction 1 Answer