Shoot to X,Y problems

forkliftforklift Member Posts: 386
edited November -1 in Working with GS (Mac)
Admittedly, I started the game prototype in iphone landscape, but switched to ipad landscape... maybe that's the problem. However, I have an actor shooting to x,y in the following manner.

screen W 2048 x H 768
camera W 1024 x H 768

When mouse is pressed
- spawn 'bullet' actor
--vector to angle (game.mouse.x - self.position.x, game.mouse.y - self.position.y)

And this works - partially. It will fire where i press the mouse button until the actor moves to what feels like outside of a 1024 W box from the start location, then the mouse firing x,y tracking gets completely off. But when i move the actor back inside that magic area, it tracks fine.

Think I can be missing something?

Comments

  • forkliftforklift Member Posts: 386
    Yes, basically when it leaves the initial camera area. Camera is set to track the player's actor and wrap X. Will check the link now.

    *EDIT* That link looks like it will fix the problem. Thanks for the heads up! I'll be back if problems persist. As always, this forum is really what makes GS awesome.
  • ORBZORBZ Member Posts: 1,304
    You need to adjust your math when computing mouse position to take the camera position into account.
  • forkliftforklift Member Posts: 386
    Ok, so I messed with the logic all night and couldn't figure out how to implement it correctly. I understand the thread link, but it deals with a slightly different logic of 'move where touched' instead of 'vector to angle'. I realize I'm supposed to adjust camera position, but how do I do that with a vector to angle problem?

    I've constrained a global camera attribute to a prototype like so:

    Constrain Attribute: game.CameraX To: Scene.Camera.Origin.X
    Constrain Attribute: game.CameraY To: Scene.Camera.Origin.Y

    But it doesn't work as written below:

    When mouse is pressed
    - spawn 'bullet' actor
    --vector to angle (game.mouse.x - self.position.x + game.CameraX, game.mouse.y - self.position.y + game.CameraY)

    I've tried a ton of variations (spent 3 hours on it last night, 6 hours total), even constraining the (game.mousex - self.position.x) to calculate that by itself and add game.cameraX in the vector to angle, but still nothing. I feel like I'm way off... insight?
  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    Double check that the attributes are selected from the attribute browser and the expression is formed correctly. (No extra parenthesis, etc)

    vectorToAngle( game.Mouse.Position.X + game.CameraX - self.Position.X , game.Mouse.Position.Y + game.CameraY - self.Position.Y )

    Also relative to actor.

    See/download the example project. http://gamesalad.com/game/play/85077
  • forkliftforklift Member Posts: 386
    @CodeMonkey

    I noticed you changed the place of '+ camera' relative to the 'mouse position'. I will try your way and thanks for the demo!

    Mine:
    vector to angle (game.mouse.x - self.position.x + game.CameraX, game.mouse.y - self.position.y + game.CameraY)

    Yours:
    vectorToAngle( game.Mouse.Position.X + game.CameraX - self.Position.X , game.Mouse.Position.Y + game.CameraY - self.Position.Y )

    Will update if it worked or not.
  • forkliftforklift Member Posts: 386
    I've spent some time away from this, working on other projects until last night. I was determined to stay up til it was finished. Here's the update: CodeMonkey, your example didn't work, sorry.

    But I am happy to report that after a total of close to 10 hours of different formulas, the problem is fixed. The logic:
    When mouse is pressed
    - spawn 'bullet' actor
    --vector to angle (game.mouse.x - self.position.x + game.CameraX, game.mouse.y - self.position.y + game.CameraY)"

    Does work. The problem was in something totally different and so dumb that I didn't feel the slightest bit of relief that the problem was fixed.

    Let this be a lesson to all the new guys: The instance where the camera constraints were located was being affected by gravity... hence falling off my scene into limbo. So no wonder the camera coordinates weren't working. The dumb thing kept being destroyed off-screen.

    Anyway, I made a ton of progress after that, so I've almost got a complete prototype. I should be finished with the rest of the prototyping by the end of this week. Thanks for all the pointers.
  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    Heh. Gravity is a harsh mistress.
Sign In or Register to comment.