❇❇ ╠╣ow to make a draggable platform (with offset) ❇❇
lukey5227
Member Posts: 111
╠╣ow to make a draggable platform
Its easy enough to make a platform stick to your mouse on the x axis, for a game like brick. Dragging and moving around a platform is a little bit harder.
STEPS
1) Create the actor
First, make your actor, drag in your image, and have it on the screen all ready to go.
2) Make a new rule
In the rule, make an "On click" and "When mouse is INSIDE the actor". That way, you'll only be able to drag when you click inside the actor. You can remove this if you want the user to be able to click anywhere and still drag the platform.
3) Make 2 new attributes
The first attribute saves the starting position of the platform.
The second attribute will save the mouse click position.
4) Use the "Change Attribute" behavior
Change the new attribute to Self.Position.X so it saves the starting position. Do NOT put this inside the rule.
4) Use the "Change Attribute" behavior inside the rule.
Make another Change Attribute and add it inside the rule. Change the attribute Self.Mouse-Click to Devices.Mouse-Position.X to save the position of the mouse when it clicks to move the platform.
5) Constrain attribute
You're going to constrain the Self.Position.X to Max(100,Min(300,(Self.Start-Position + (Devices.MousePosition.X - Self.Mouse-Click))))
This is how Step 5 works:
Max always gives the lowest value so if the mouse is farther than 100, the higher value is 100 so it will have 100. For min, the lowest value is always returned. Since 300 is inside min, if between the two numbers 300 is the lowest, 300 will be in the constrain. Otherwise, the other number will be returned to the constrain.
We start off with the Start position of the platform. We're going to add how much the mouse has changed. Pretend the start position of the mouse is 150 pixels. If we click and than move the mouse to the right 5 pixels, the starting position minus the new position, which is 155, is 5 pixels. Add that to the original platform position (ex: 140) and you'll get the platform at 145.
Why we do this: The reason we add this complex thing rather than just putting the mouse position is because of the offset. We don't want the platform to jump to a position when we click. Rather, it moves the amount of pixels we've moved the mouse.
100 and 300 can be changed. In fact, when you drag on a new platform, unlock it. Then, edit the max and min of the platform so you can have platforms move different amounts!
Tip: Make a max and min attribute and add it inside where normally would be the min and max. This way, you don't have to unlock the actor. Just change the attributes!
5227 Tutorials
Comments