The vector angle is calculated by: this.angle = this.angleToPoint(new me.Vector2d(e.gameX - 30, e.gameY + 30));
The attacks are launching off towards the top left of the map (this is a top-down 2D rpg with gravity turned off), even though I am clicking towards the bottom right.
You can see here, I'm console.logging the vectors after applying appropriate trigonometry. The first click is towards the bottom right, then towards the top left, then 2 more towards the bottom right. The angles and calculations are changing as expected, but the trajectory of the attack is still heading towards the top left:
http://i.imgur.com/skIEoNv.png
A Github GIST:
https://gist.github.com/dtturcotte/9a26e996da623a13dfc7a97cf52be1a7
Why is this?
The Math.atan2() method returns a numeric value between -π and π representing the angle theta of an (x, y) point. This is the counterclockwise angle, measured in radians, between the positive X axis, and the point (x, y).
this.body.vel.set(Math.cos(-this.angle) * this.speedMultiplier, -Math.sin(-this.angle) * this.speedMultiplier);
--
You received this message because you are subscribed to the Google Groups "melonJS - A lightweight HTML5 game engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to melonjs+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to melonjs+unsubscribe@googlegroups.com.
if ((response.a.type === 'PlayerEntity')) {
To unsubscribe from this group and stop receiving emails from it, send an email to melonjs+unsubscribe@googlegroups.com.
game.AttackEntity = me.Entity.extend({
init: function(x, y, settings) {this._super(me.Entity, 'init', [x, y , settings]);this.body.collisionType = me.collision.types.PLAYER_OBJECT;this.body.setCollisionMask(me.collision.types.WORLD_SHAPE | me.collision.types.ENEMY_OBJECT);// ...
if (collidedObject.body.collisionType === me.collision.types.ENEMY_OBJECT)
To unsubscribe from this group and stop receiving emails from it, send an email to melonjs+unsubscribe@googlegroups.com.