How to make the actor not jump to mouse position?

AtlantenAtlanten Member, PRO Posts: 56
edited November -1 in Working with GS (Mac)
I have an actor that can be moved around, you click on it and drag it to another position. So the actor's position gets constrained to the mouse position when you click on it.

When you click on the actor somewhere off-center, it jumps to position itself centered on the mouse click point, and it doesn't look so good...

How can I write an expression to make the actor keep its relative position to the mouse click, but still follow it around?

Thanks

Comments

  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    Store the position of the actor when it is clicked relative to the mouse.

    Real Attributes: self.OffsetX and self.OffsetY
    Boolean Attribute: self.grabbed.

    Rule: when touch(pressed) or mouse down&mouse position over.
    --Change Attribute: self.OffsetX = game.mouse.Position.X - self.Position.X
    --Change Attribute: self.OffsetY = game.mouse.Position.Y - self.Position.Y
    --Change Attribute: self.grabbed = true

    Rule: When Attribute: self.grabbed=true
    --Constrain Attribute: self.Position.X = game.mouse.Position.X - self.OffsetX
    --Constrain Attribute: self.Position.Y = game.mouse.Position.Y - self.OffsetY

    I think that should work
  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    Store the position of the actor when it is clicked relative to the mouse.

    Real Attributes: self.OffsetX and self.OffsetY
    Boolean Attribute: self.grabbed.

    Rule: when touch(pressed) or mouse down&mouse position over.
    --Change Attribute: self.OffsetX = game.mouse.Position.X - self.Position.X
    --Change Attribute: self.OffsetY = game.mouse.Position.Y - self.Position.Y
    --Change Attribute: self.grabbed = true

    Rule: When Attribute: self.grabbed=true
    --Constrain Attribute: self.Position.X = game.mouse.Position.X - self.OffsetX
    --Constrain Attribute: self.Position.Y = game.mouse.Position.Y - self.OffsetY

    I think that should work
  • AtlantenAtlanten Member, PRO Posts: 56
    Ooh, that works perfectly

    Thank you so much
  • HunnenkoenigHunnenkoenig Member Posts: 1,173
    That is awsame! Thanks!

    I was thinking too complicated and I wanted to count magnitude and subtract that value from the positions :-)

    Since I have learned magnitude, I seem to be attached to it somehow :-P

    This is exactly what I was looking for. Thanks!
  • synthesissynthesis Member Posts: 1,693
    Thanks for bumping this Hunn. Good stuff here!
  • StormyStudioStormyStudio United KingdomMember Posts: 3,989
    thats amazing....I was willing to ignore this annoying feature of my game, but it can be fixed....look forward to implementing that tonight...

    hmm... has my life got to the point where all I want to do on an exciting evening is implement new rules...someone please kill me.... but wait till I've added the code..
  • HunnenkoenigHunnenkoenig Member Posts: 1,173
    @draper3000: the time will come, when your excitement will be, when you can pee without pains :-)
    Wait with killing until then :-)
  • StormyStudioStormyStudio United KingdomMember Posts: 3,989
    that works a treat...amazing...many thanks to CodeMonkey.

    Due to my own stupid confusion over booleans, as to whether you can write 'true' or 'false' or whether to put numbers '1' or '0' in.

    I changed it a tiny bit, making self.grabbed an integer.

    Then having it so when pressed

    self.grabbed = 1

    then in the otherwise box (so essentially when not pressed)

    self.grabbed = 0

    so it resets it ready for something else to be grabbed.
  • StormyStudioStormyStudio United KingdomMember Posts: 3,989
    OK QUESTION:

    i've got an object that moves when grabbed (now using the way above..).

    It also rotates to the angle of a 2nd touch...
    using rotate to position, of 2nd touch X and 2nd touch Y.

    This works, but it rotates around the centre of the object not where it has now been grabbed. Is it possible to use the offset from above to change where it rotates?
Sign In or Register to comment.