I want to create a scene where the player can roam around the certain space.
And by the end of the game, I want to analyze where the player stayed the longer or moved the least, and have a output of the data in terms of transform.
(next step would be using the output to place an object on the spot)
I want to try in java-script (which i am learning currently), and
would love to have some guidance by professionals.
You actually don’t need to save the player transform (this wouldn’t work anyway): just save its position (and rotation, if object must match player orientation).
A simple way would be to monitor the player movement each frame, counting the time it stays in the same position and saving the highest time - like this (attach it to the player):
var margin: float = 0.1; // tolerance margin to be considered stopped
var pos: Vector3; // position where it stayed most time
private var biggestTime: float = 0.0;
private var lastPos: Vector3;
private var time: float; // time currently stopped
function Start(){
lastPos = transform.position;
}
function Update(){
// if player moved out of margin...
if (Vector3.Distance(transform.position, lastPos) > margin){
// save current position and zero timer:
lastPos = transform.position;
time = 0;
} else { // if still inside margin...
time += Time.deltaTime; // increment timer
if (time > biggestTime){ // if greatest time till now...
biggestTime = time; // register it...
pos = lastPos; // and the position
}
}
You can read pos at any time to know where the player stayed the most.