Fire Based on Touch Location with Scrolling Screen

RawrMalarRawrMalar Member Posts: 2
edited August 2013 in Working with GS (Mac)
Hello,

I'm new to GameSalad and have an issue with the player firing a projectile. The goal is to have it "lob" in some manner so that the player effectively sets the range of the missile by where he/she touches in relation to the player. The way I've been approaching this is to have the missile have a total speed, like 250. Then I base the velocity in the x-direction on where the user touched the screen - the formula being 250 * cos(vectorToAngle(mouse.X - player.X, mouse.y - 176)). Then the y velocity is just the same but with sin. The missile is affected by a downward acceleration for the lob effect.

The y-coordinate in the formula isn't the issue as the 176 is fixed (the player only moves left and right). The issue is the x-coordinate when factoring in that the screen scrolls. It seems that the mouse.X will always been within the confines of the camera size. So if your screen is larger than the camera, the formula gets thrown off completely.

Let's say you're camera size is 400 in width (we can ignore the y aspect of the problem as it isn't an issue), and the screen size is 800 in width. Once the camera moves to follow the player past 400, issues arise because the touch will be, at the furthest in the x-direction, 400. So even if the player is in the center of the screen, let's say at 600, and you touch at what should be 800, the mouse.X reports 400, and the projectile is thrown in the opposite direction entirely.

I'm not sure how to fix this outside of being able to directly reference the camera position in order to offset the formula correctly, but it doesn't appear that I can do that.

Any help is appreciated,

Thanks!

Comments

  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    Look at the video on the cookbook YouTube on constraining to mouse on large scenes it will show you the solution.
  • RawrMalarRawrMalar Member Posts: 2
    Thanks, that seems to be what I need exactly. Didn't know that "unlocking" an actor would open up the ability to reference the camera origin for it.
  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    Ah see you learn something new all the time. This is why it's good just to watch the videos even if you're not doing the specific thing in the title of the video. All the videos show you how to code in GS and the techniques can be applied to countless things not just the videos topic. Once armed with more information you begin to become a power user in GS.
Sign In or Register to comment.