How to make the actor not jump to mouse position?
Atlanten
Member, PRO Posts: 56
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
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
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
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
Thank you so much
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!
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..
Wait with killing until then :-)
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.
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?