to see how to access z and it crashed on compile. (as in - using chrome, I get the aw snap - crash page) Now It crashes every time, and cant access the code I wrote.
@nick, I’d really like that code .
and how do I get in to this level
and why cant I access Z
I think that code crashes because it’s 1) converting a ton of Vector function properties to strings, 2) concatenating all those together a ton of times into one long string, and 3) serializing a huge, constantly changing string from the web worker to the main thread once for every frame of the simulation. So the code is slow and unperformant because of 1) and 2), but probably step 3) is what is crashing it, because my serialization code can’t handle so many huge strings getting sent across the web worker boundary at once.
The reason you can’t access z is because it’s not in the Vector’s API, since we intended that all the gameplay be basically in 2D and have the z-dimension just be aesthetic for almost all cases. Are you trying to use it just to see if the enemy is jumping, or is there another use case for knowing it?
You can save his current position in this.enemyLastPos and compare distance the following frame. If his distance is greater than his movement speed provides (not sure what it is off hand) then he would be jumping. If it’s lower, he might be jumping, but using it ineffectively.
I think what’s going on is that this is no longer Tharin inside your sort callback–it’s the anonymous sort function. So when you call a.distance(this), it tries to find pos on this, but this (the sort function) has no pos. You could do something like this:
var tharin = this;
items.sort(function(a, b) {
// ...
if(a.distance(tharin) > b.distance(tharin)) {
// ...