Motion of swipe in real time to another actor
I have actorA at position 100,100 and actorSwipeControl at any position that covers the entire screen. I would like to be able to touch the screen at a position(say 500,200... but any position needs to work) and as I move my finger, have it alter actorA's position by the amount my finger moved, all in real time.
I can't figure out how to get the correct value out of this though. I should be able to take something like the difference between actorSwipeControl.firstTouch and the current touch position, but I can't figure out the proper formula to apply, and how to constrain the values. If anyone can help me, I'd really appreciate it.
I can't figure out how to get the correct value out of this though. I should be able to take something like the difference between actorSwipeControl.firstTouch and the current touch position, but I can't figure out the proper formula to apply, and how to constrain the values. If anyone can help me, I'd really appreciate it.
Comments
In an actor, make two (real) attributes: xOffset, yOffset
Then make a rule:
When mouse down
-- Change Attribute: self.xOffset To: game.Mouse.Position.X - self.Position.X
-- Change Attribute: self.yOffset To: game.Mouse.Position.Y - self.Position.Y
-- Constrain Attribute: self.Position.X To: game.Mouse.Position.X - self.xOffset
-- Constrain Attribute: self.Position.Y To: game.Mouse.Position.Y - self.yOffset
That should get things started!
But I'm pumping out ideas quick as lightning, so I'm loving this program.
I do agree with you. GameSalad's great interface and methodology really frees us from the the constraints of conventional coding. It encourages ideas to just flow "quick as lightning" as you say.
When mouse button is down{
Change self.positionY to game.mousePositionY
Constrain self.motion.linearVelocity.Y to 20*( game.Mouse.Position.Y - self.Position.Y )
} else {
Constrain self.motion.linearVelocity.Y to self.Motion.Linear Velocity.Y *0.95
}
Constrain game.dragVelocity to self.Motion.Linear Velocity.Y
}
Then I simply placed the actors that I wanted to drag, and:
Constrain self.motion.linearVelocity.Y to game.dragVelocity
The actors then move with the same speed that I am swiping. I actually added a few more constraints to the rule in the drag actor to limit the swiping to a certain area of the screen:
game.mousePosition.X > 20
game.mousePositionX < 200
game.mousePositionY > 370
game.mousePositionY < 730
These are of course variable and irrellevant.
A big thanks to tshirtbooth's tutorial vids on getting this method working. I cant wait to demo this app out to you guys. Any parents out there should get a kick out of my app.
Edit----
Here is another variation that might be less processor intensive. It allows the rest of the physics engine to play nice with the actor. And it does not require an extra drag actor. (It does require you to define one attribute -- yOffset.) Just place the following into the regular actor:
Change Attribute: self.Physics.Drag To:100
When MouseDown
-- Change Attribute: self.yOffset To: game.Mouse.Position.Y-self.Position.Y
-- Constrain Attribute: self.motion.Linear Velocity.Y To: 20*(game.Mouse.Position.Y-(self.Position.Y +self.yOffset))
It works a charm and looks really nice. You're solution will work great with my side project though. Thanks for sharing that.