Jump to content

math.angleBetween() doesn't work as supposed to


kaasis
 Share

Recommended Posts

Hi!

I had this issue at very start when i started using Phaser but was always lazy to create topic about this. I searched everywhere and even tried different methods from google but none worked. The thing is that, it works actually, only if you don't use camera.follow(), without it works perfectly fine. But i when you use camera.follow() then it suddenly gives false values. So far i have used Phaser's Arcade's physics angleBetween() that works perfectly fine with camera.follow() and without it. But i don't want to use Physics as it slows down a bit performance and i don't even use any type of physics anyway 'cause my game is top down and i handle all my stuff without it anyway, so i don't see point using arcade physics just for angle rotation. If there are any solutions for this without using Physics, then comment down. Thanks in advance!

Link to comment
Share on other sites

2 hours ago, samme said:

Can you say exactly how you're using Math#angleBetween and Arcade#angleBetween?

// using arcade's built in (works)
this.player.rotation = this.physics.arcade.angleToPointer(this.player)

// using math function (doesn't work)
this.player.rotation = this.math.angleBetween(this.player.x,this.player.y,this.input.mousePointer.x,this.input.mousePointer.y)

 

Link to comment
Share on other sites

Hi, @Antriel is correct. If you inspect the source code of the angleToPointer function, you will find that it calculates using pointer.worldX. So if you want to use angleBetween, you have to pass worldX/Y...

You don't really rely on arcade physics when using angleToPointer. Here is an example to demonstrate (the custom function is the exact same as arcade.physics.angleToPointer) :

 

Link to comment
Share on other sites

16 hours ago, kaasis said:

@Antriel yup worked. Didn't know it has 2 ways to get mouse position. Thanks!

@samid737 and yeah, it actually doesn't really use arcade physics by itself if you use only angleToPointer by looking at that source code.

Me neither! Glad to clearify it..

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...