Hi i have got a problem that i can't work out how to fix without break my code. i was wondering if anyone could possibly help change my code below.
What this code does, is that tells the game objects to go to their end points, which are empty game object that act as reference points in virtual space, by a click of a GUI button.
At the moment the code works but it snaps the object to their end point instead of flowing (so you get to see the movement from A to B)
What i want to achieve is this "flow movement" and i have been told in the past that this can be done with delta.time or something on the lines of that.
I would be grateful for any help thank you.
//Written by Will Poole "Explode Script" 6/12/10
asked Dec 07 '10 at 11:36 AM
Try this code. You need to call StartCoroutine with Move for each pair of object you got.
answered Dec 07 '10 at 04:06 PM
Assigning the position like this doesn't even show the movement from A to B. Assigning the position simply jumps to B. Flowing? I'm not sure exactly what you mean by this as we aren't talking about a fluid simulation or anything, but I'll assume that you mean moving or moving with easing.
A few notes:
To move to the position from A to B, you would probably want to use Lerp. To get constant movement, you would store the start position as well as the end. Something like:
If you want to store the start without having to have another transform for it, you could do something like this:
To ease in only towards the end, you can Lerp from subject.position to the end.position, but then your movement is framerate dependent. When doing this, you typically want to lerp by some fixed amount as if you were to lerp with Time.deltaTime, when your frame takes a longer amount of time, your movement would move by larger amounts and for a frame that took 1 second, your subject would jump to the end.position. The other concern is that unless you use Time.deltaTime and a frame takes 1 second, your subject will never reach end exactly, but will be approaching it forever so you cannot compare the two positions for equality (which is generally not a safe idea anyways). To aleviate framerate dependencies, you can place the movement in FixedUpdate.
This setup doesn't seem very scalable. If you add or remove objects, you need to change the script. You might be better off having a control script and a movement script on the objects you want to move:
MoveButton.js (put this on the camera or something)
Mover.js (put this on each object you want to move)