How to Constrain To Mouse With An Offset Camera?

TouchTiltGamesTouchTiltGames Member Posts: 1,162
edited January 2012 in Working with GS (Mac)
Hey guys, I'm using TSB's ConstrainToMouse template found here: http://gshelper.com/?p=377 for picking up and dropping objects. It's awesome except that it doesnt work if my camera origin is elsewhere. (My scene is 30,000px wide) How can i adjust it so it will work if the camera origin is not at it's default?
I'm guessing I'd have to do something at the scene/instance level since you can only do camera/constraining at the scene level.

Any hint would be much appreciated!
cheers.

Comments

  • Braydon_SFXBraydon_SFX Member, Sous Chef, Bowlboy Sidekick Posts: 9,273
    I believe you need to change the Camera's origin if I understand the question correctly.
    For my Game, Penguin Pounce, I needed to change the X position of my camera origin to 477.
  • scitunesscitunes Member, Sous Chef Posts: 4,047
    any place you have mouse.position.X or touch.position.X change it to "mouse.position.X + camera.origin.X" same thing for touch. Also same thing for y but of couse using camera.origin.y.

    You'll need to unlock the instance to get at the camera settings
  • TouchTiltGamesTouchTiltGames Member Posts: 1,162
    Thanks Sci, Doesn't seem to be working for me. Wish I could upload the TSB template to you right here!
  • simo103simo103 Member, PRO Posts: 1,331
    edited January 2012
    @TouchTiltGames ... see if this i what you are looking for:

    http://www.funkymunkygames.com/promo/constraintomouse_bigscreen.gameproj.zip

    Note: in the scene actor (bomb) I had to add camera.origin.X and Y twice (once in this rule: 'when touch is pressed grabbed to true' and the second in the constrain rules). I also added a camera control.
    Also there were some invisible walls in there that blocked movement so I have removed them but you may want to wall in the outside of the scene so the bomb doesn't travel out of sight.
  • scitunesscitunes Member, Sous Chef Posts: 4,047
    could it be a parentheses problem?

    so for example if the game.mouse.position.X is in an equation you will need to add the camera origin with parentheses:

    (game.mouse.position.X+current.scene.camera.origin.X)

    maybe that's the problem
  • TouchTiltGamesTouchTiltGames Member Posts: 1,162
    Here I've copied out the lines where there's a Mouse or Touch:

    When mouse button is down
    self.touchdistance > magnitude( self.Position.X - game.Mouse.Position.X + scene.Camera.Origin.X , self.Position.Y - game.Mouse.Position.Y + scene.Camera.Origin.Y )
    change self.grabbed = true

    When self.grabbed is True
    self.motion.linear velocityX to: 20*( game.Mouse.Position.X + scene.Camera.Origin.X - self.Position.X )
    self.motion.linear velocityY to: 20*( game.Mouse.Position.Y + scene.Camera.Origin.Y - self.Position.Y )
  • TouchTiltGamesTouchTiltGames Member Posts: 1,162
    @simo Yes I think that's it. I'll try this on mine but yeah it seems basically the same in that my scene is large, my camera is offset etc. Thanks guys!
  • TouchTiltGamesTouchTiltGames Member Posts: 1,162
    Annnnd it worked! Looks like it was the forgotten brackets there. Thanks so much guys!
Sign In or Register to comment.