Quantcast
Channel: Latest Questions by Lunaria
Viewing all articles
Browse latest Browse all 24

How to check transform by frame?

$
0
0
Hello, Developers. I'd like to check difference between now frame and previous frame. So, I wrote a code like below. public class Test : MonoBehaviour { Transform oldPosition; Transform newPosition; // Use this for initialization void Start () { // Allocate previous Frame's data oldPosition = GameObject.Find("TestObject"); ... } // Update is called once per frame void Update () { float old_x = oldPosition.rotation.x; float old_y = oldPosition.rotation.y; float old_z = oldPosition.rotation.z; // Allocate now Frame's data newPosition = GameObject.Find("TestObject"); float new_x = newPosition.rotation.x; float new_y = newPosition.rotation.y; float new_z = newPosition.rotation.z; // Calculate difference between now and previous float cal_x = new_x - old_x; float cal_y = new_y - old_y; float cal_z = new_z - old_z; ... // **It shows 0, 0, 0!** Debug.Log ("x : " + cal_x + " y: " + cal_y + " z: " + cal_z); // Switch now Frame to previous Frame oldPosition = newPosition; } } I thought that from Start() to Update() takes a few frames. But the result was same. the data allocated in Start() and the data allocated in Update() was same. The data doesn't same at all. It must not. What shoud I do for fixing this code?

Viewing all articles
Browse latest Browse all 24

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>