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 Joncom

My entity is supposed to move in straight line toward the mouse, but he's not. Here's a working demo to show you what I mean.

Also a screenshot.

/><br />
The red lines indicate the approximate path my mouse took. As you can see from the exhaust trail, the ship didn't take the same path.<br />
<br />
Here's relavant code:<br />
<br />
<pre class= EntityPlayer = ig.Entity.extend({ movementspeed: 400, init: function(x, y, settings) { this.parent(x, y, settings); this.addAnim('idle', 1, [0], true); }, update: function() { this.parent(); this.move_toward_coord(ig.input.mouse.x, ig.input.mouse.y); }, move_toward_coord: function(x, y) { var distance_to_target_x = x - this.pos.x - this.size.x / 2; var distance_to_target_y = y - this.pos.y - this.size.y / 2; if(Math.abs(distance_to_target_x) > 1 || Math.abs(distance_to_target_y) > 1) { this.vel.x = (distance_to_target_x > 1 ? 1 : -1) * this.movementspeed * (Math.abs(distance_to_target_x) / (Math.abs(distance_to_target_x) + Math.abs(distance_to_target_y))); this.vel.y = (distance_to_target_y > 1 ? 1 : -1) * this.movementspeed * (Math.abs(distance_to_target_y) / (Math.abs(distance_to_target_x) + Math.abs(distance_to_target_y))); } else { this.vel.y = 0; this.vel.x = 0; } } });
Why is my entity not moving in a straight line?

1 decade ago by Joncom

Ughh!! I feel so silly now. It was because maxVel was not set (or rather the default was too low). This fixed it:

maxVel: { x: 400, y: 400 }
Page 1 of 1
« first « previous next › last »