1 decade ago by Jarkko
Ok, I think there must be a simple explanation for this, but I'm just too thick to get it.
I have an entity that follows the mouse. The following is the code from the update() method of the entity:
The problem is, the mouse-following entity completely ignores the collision map.
But when I replace pos.x, pos.y with vel.x, vel.y, then it collides properly.
I can live with that, but I don't understand why this is the case? Does setting position explicitly like this somehow override the collision testing?
I have an entity that follows the mouse. The following is the code from the update() method of the entity:
if (this.follow) { var EASING = 0.03; var dx = ig.input.mouse.x - this.pos.x; var dy = ig.input.mouse.y - this.pos.y; //var dx = this.pos.x - ig.input.mouse.x; //var dy = this.pos.y - ig.input.mouse.x; var rotation = Math.atan2(dy, dx); this.currentAnim.angle = rotation; var distanceSquared = (dx * dx + dy * dy); if (distanceSquared >= 9) { this.pos.x += dx * EASING; this.pos.y += dy * EASING; }
The problem is, the mouse-following entity completely ignores the collision map.
But when I replace pos.x, pos.y with vel.x, vel.y, then it collides properly.
I can live with that, but I don't understand why this is the case? Does setting position explicitly like this somehow override the collision testing?