9 years ago by Vash
Hello friends.
I need some help with collision detection, eighter touches() or distanceTo()
Got 2 Entities. If both are set to
size: {x:30, y:30},
distanceTo works fine. it would output 60 to console.
whilst one player entity at (30,30) vs one damaging entity with size (20,20) outputs 44 on the left side and 54 on the right boundary
im drawing both with canvas context as follows:
ctx.arc(this.pos.x, this.pos.y, this.size.x, 0, Math.PI*2);
and i guess there might be a radius problem. size.x/2 to have a 30x30 hitbox but a 15x15 character didnt solve it.
long story short:
center point playerX and entityX while in collision seems to be offset. entity is getting spawned at playerX
if i move playerX a tiny bit to the left, distance will be decreased from ~7.1 to ~5.x
wich makes no sense.
thank you and may your journey with your friend .js be with less chaos theory
I need some help with collision detection, eighter touches() or distanceTo()
Got 2 Entities. If both are set to
size: {x:30, y:30},
distanceTo works fine. it would output 60 to console.
whilst one player entity at (30,30) vs one damaging entity with size (20,20) outputs 44 on the left side and 54 on the right boundary
var len =ig.game.getEntitiesByType(EntityGlobe).length; for(var i=0; i<len; i++) { var dist = this.distanceTo(ig.game.getEntitiesByType(EntityGlobe)[i]) console.log(dist); }
im drawing both with canvas context as follows:
ctx.arc(this.pos.x, this.pos.y, this.size.x, 0, Math.PI*2);
and i guess there might be a radius problem. size.x/2 to have a 30x30 hitbox but a 15x15 character didnt solve it.
long story short:
center point playerX and entityX while in collision seems to be offset. entity is getting spawned at playerX
if i move playerX a tiny bit to the left, distance will be decreased from ~7.1 to ~5.x
wich makes no sense.
thank you and may your journey with your friend .js be with less chaos theory