touch and drag actor

Player_EPlayer_E Member, PRO Posts: 604

So, I've been working on trying to put something together where I press and hold an actor and drag it along the screen, when I let it go I want it to slide back to its original position.

I have the basics down, when actor is pressed constrain x and y position to the mouse position
when touch is released I interpolate the actor back to its original position.

This all works fine and dandy, but I don't like the way the constrain X and Y attribute looks when Im dragging the actor around, its too precise and doesn't have a good ascetic appeal. I would like for it to have a tiny bit of a lag (just like when you are moving app icons around on the iPhone home screen).

Ive tried "move to" but it causes some issues with the actor interpolate back to original position.

Anyone have a good method from dragging an actor?

Comments

  • SLOCM3ZSLOCM3Z Member Posts: 797

    When touch is pressed use a timer. Every 0.2 constrain attribute x and y to mouse

  • MentalDonkeyGamesMentalDonkeyGames Member Posts: 1,276

    Try something like this.

    Mental Donkey Games
    Website - Facebook - Twitter

  • SocksSocks London, UK.Member Posts: 12,822
    edited October 2015

    @Player_E said:
    Anyone have a good method from dragging an actor?

    There are numerous ways to do this, here's another one . . . .

    When touch is pressed
    --Constrain self rotation to: vectorToAngle(Mouse X-self X, Mouse Y-self Y)
    --Move: Dir 0°: Relative - Actor: Speed: magnitude(Mouse X-self X, Mouse Y-self Y)*2

    The '*2' part controls the smoothness. *1 is smooth as butter, *10 is more reactive, but still takes the mechanical edge off a direct constrain to mouse.

    I've included a picture of some butter to help you imagine how smooth *1 is:

  • SocksSocks London, UK.Member Posts: 12,822
    edited October 2015

    Here's another method:

    When touch is pressed
    --Constrain Linear Velocity X to 5* (mouse X - self X )
    --Constrain Linear Velocity Y to 5* (mouse Y - self Y )
    --Constrain Rotation to vectorToAngle(Linear Velocity X, Linear Velocity.Y )
    . . . . . . . .
    Otherwise
    --Change attribute Linear Velocity X to 0
    --Change attribute Linear Velocity Y to 0

  • SLOCM3ZSLOCM3Z Member Posts: 797

    @Socks! That looks very smooth!

  • SLOCM3ZSLOCM3Z Member Posts: 797

    @Player_E... there are a lot of answers for you :D

  • SocksSocks London, UK.Member Posts: 12,822

    @jdlcrater said:
    Socks! That looks very smooth!

    It's the smoothest drag in the whole of the app world, it's used extensively in butter related apps.

  • SocksSocks London, UK.Member Posts: 12,822

    P.S . . . . . for the first version I posted above, this one . . .

    When touch is pressed
    --Constrain self rotation to: vectorToAngle(Mouse X-self X, Mouse Y-self Y)
    --Move: Dir 0°: Relative - Actor: Speed: magnitude(Mouse X-self X, Mouse Y-self Y)*2

    . . . the slide back to its original position would be placed in the otherwise section and would look like this:

    When touch is pressed
    --Constrain self rotation to: vectorToAngle(Origin X-self X, Origin Y-self Y)
    --Move: Dir 0°: Relative - Actor: Speed: magnitude(Origin X-self X, Origin Y-self Y)*2

    (Origin X and Origin Y are the coordinates for where you want it to return to)

  • Player_EPlayer_E Member, PRO Posts: 604

    Awesome guys!

    I posted right before walking out the door for work, but glad there are so many other options.

    I'll check them out tonight asap!

    Thanks again

  • SocksSocks London, UK.Member Posts: 12,822
    edited October 2015

    @Player_E said:
    Awesome guys!

    I posted right before walking out the door for work, but glad there are so many other options.

    Here's another, a slightly slimmed down version of the above (all these variations offer different advantages / options):

    When touch is pressed:
    --Move:
    ----Dir: vectorToAngle(mouse X - self X, mouse Y - self Y)
    ----Speed: magnitude (mouse X - self X, mouse Y - self Y) *2
    . . . . . . . . . . . . . . . .
    Otherwise: (spring back to starting position)
    --Move:
    ----Dir: vectorToAngle(Origin X - self X, Origin Y - self Y)
    ----Speed: magnitude (Origin X - self X, Origin Y - self Y) *10

    (spring back looks better when the multiplier (the '*10' part) is bigger in the otherwise section than in the main section)

  • cbtcbt Member Posts: 644

    AaaaaaaAAAaa

  • Player_EPlayer_E Member, PRO Posts: 604
    edited October 2015

    Thanks for all the help guys.

    I went with the last method you posted socks, but in the otherwise section, I left the interpolate rules. I like the way those look :)

  • Titanical Tech ProductionTitanical Tech Production Member, PRO Posts: 35

    When moving multiple people at the same time, it goes to touch 1 which is actor 1. When I changed it to touch 2, it works fine. However, when I released the touch on actor 1, actor 2 goes crazy and glitches in the scene.

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,937

    @Titanical Tech Production That's not enough information to solve the issue you're having. We'd need to know what rules you're using for each actor related to touch.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • Titanical Tech ProductionTitanical Tech Production Member, PRO Posts: 35

    Here is a screenshot of the rules. I took @Socks suggestion except changed the mouseX and MouseY to TouchX and TouchY.

  • Titanical Tech ProductionTitanical Tech Production Member, PRO Posts: 35

    By the way it is applied to both actors.

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,937

    The most important part of that screenshot is... hidden:

    You can either click on the 'e' symbols and take another screenshot or just click on the 'e' symbols and then highlight each expression and copy and paste them (as text) into a comment.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • Titanical Tech ProductionTitanical Tech Production Member, PRO Posts: 35
    edited November 2018

    ( game.Touches.Touch 1.X - self.Position.X ) * 10
    ( game.Touches.Touch 1.Y - self.Position.Y ) * 10
    This is applied for both player 1 and player 2

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,937

    So the player 2 actor uses game.Touches.Touch 2.X and Y?

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • Yes and what happens is when I let go of touch 1 then the AI cannot think and cannot decide which touch is engaged so the actor spins around the scene and causes glitches so the game is unplayable.

Sign In or Register to comment.