Vectortoangle not working properly in large scenes

So the idea is I want the player actor to shoot a projectile towards the mouse position. I am using Vectortoangle to try to do this. My code for getting the angle is:

vectortoangle(game.mouse.position.x-self.position.x, game.mouse.position.y-self.position.y)

And it saves that to an angle attribute which the projectile uses to move. The problem is, I have a scene that is 320x1280 and the player actor starts at the top and moves downwards. The camera is 320x480 and follows the player actor. When it is near the top of the screen, all the projectiles will fire generally down, no matter where you click, until you pass a certain point, then they will fire towards the mouse like they should.

I think the problem is that vectortoangle is using the mouse x and y from it's position within the camera but the player actor's position relative to the whole scene. For example, the first time my vectortoangle activates, the mouse position is around 160,320 but the player actor's position is around 160, 1000. Then it screws up vectortoangle and makes it fire almost straight down, because that's where it thinks the coordinates are.

So does anyone know of a way to either:
1. Make the mouse position be relative to the scene instead of the camera.
2. Make the actor position relative to the camera instead of the scene.

Comments

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880

    Unlock the player actor and add scene.camera.origin X to the mouse position X. (And do the same for mouse position Y ). When done it will look something like this:

    vectortoangle((game.mouse.position.x + scene.camera.originX)-self.position.x, (game.mouse.position.y + scene.camera.originY)-self.position.y)

  • irkutsk_98irkutsk_98 Member Posts: 3

    I actually managed to figure out something similar to that using scene.camera.origin. Thanks for the reply!

Sign In or Register to comment.