0

I'm learning to do some simple animations with JavaScript and canvas and trying to do some simple physics animations, where I do calculations and animate, displacement of the objects.

However, I encountered quite an odd problem when I put :

this.ax = (this.vx)^2;

Everything works just fine, but when I do :

this.ax = (this.vx)^2 + (this.vy)^2; 

nothing moves. There is work around to just put :

this.ax = (this.vx)^2 + this.vy * this.vy;

But I wonder why simply squaring or adding Math.pow doesn't do the trick here?

Edit: to try and keep code clean and consistent, I tried using this.vx * this.vx and animations were messed up again.

Nzzska
  • 1
  • 2
    The [exponentiation operator is `**`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Exponentiation) in JavaScript. – Heretic Monkey Aug 21 '20 at 13:06
  • 2
    The `^` operator is XOR in JS. Also, where did you use `Math.pow(this.vx, 2)` in your example? – Mr. Polywhirl Aug 21 '20 at 13:07
  • `^` [Bitwise XOR operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_XOR) Are you sure that exactly what you need? – Greg-- Aug 21 '20 at 13:11

0 Answers0