Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by wands

I'm trying to get the angle from my entity to another entity, but i got error messages

I got 2 js files, one is call player1.js while the other is call player2.js

Inside player1.js I have this line of code declared in the update() function
var angle = this.angleTo(EntityPlayer2);

I'm using weltmeister to load up both my entities.

Then i got this error messages. I'm not an experience coder, so would be really grateful if anyone could point out my mistake. :)

Uncaught TypeError: Cannot read property 'y' of undefined entity.js:197
ig.Entity.ig.Class.extend.angleTo entity.js:197
ig.Entity.extend.update player1.js:37
(anonymous function) impact.js:506
ig.Game.ig.Class.extend.updateEntities game.js:212
ig.Game.ig.Class.extend.update game.js:189
ig.Game.extend.update main.js:55
(anonymous function) impact.js:506
ig.Game.ig.Class.extend.run game.js:170
ig.System.ig.Class.extend.run system.js:108
animate

1 decade ago by drhayes

What you&039;re passing to #angleTo is the class; you need to pass an instance.

You know how somewhere in your code you call spawnEntity and it hands you back an object? That's what you need to pass to this call.

Your code should probably look like this:

var angle = null;
var players = ig.game.getEntitesByType(EntityPlayer2);
if (players && players.length > 0) {
  angle = this.angleTo(players[0]);
}
if (angle != null) {
  // Do whatever you need to do with the angle.
}

1 decade ago by wands

Oh so that's the problem. Thank you for pointing that out
Page 1 of 1
« first « previous next › last »