1 decade ago by Joncom
Here&
It works perfectly if
In other words between
039;s a method that sets the entity velocity when given an #angle
.setVelocityByAngle: function(angle, velocity) { var slope = Math.tan(angle); var x_factor = (Math.abs(angle) < 1.57 ? 1 : -1); // 1.57 rads ~~ 90 degrees var y_factor = (angle > 0 ? 1 : -1); var rise = (Math.abs(slope) / (1 + Math.abs(slope))); var run = (1 / (1 + Math.abs(slope))); this.vel.y = y_factor * velocity * rise; this.vel.x = x_factor * velocity * run; }
It works perfectly if
angle
is between -Math.PI
and Math.PI
.In other words between
-180
and 180
degrees.
1 decade ago by quidmonkey
Just use the standard equation:
this.vel.x *= Math.cos(angle); this.vel.y *= Math.sin(angle);
1 decade ago by Joncom
Thank you quidmonkey.
Works perfectly!
Works perfectly!
setVelocityByAngle: function(angle, velocity) { this.vel.x = Math.cos(angle) * velocity; this.vel.y = Math.sin(angle) * velocity; }
Page 1 of 1
« first
« previous
next ›
last »