GameSalad

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

touch and drag actor

Player_EPlayer_E Posts: 604Member, PRO

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 Posts: 796Member

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

  • MentalDonkeyGamesMentalDonkeyGames Posts: 1,276Member

    Try something like this.

    Mental Donkey Games
    Website - Facebook - Twitter

  • SocksSocks London, UK.Posts: 12,822Member
    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.Posts: 12,822Member
    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 Posts: 796Member

    @Socks! That looks very smooth!

  • SLOCM3ZSLOCM3Z Posts: 796Member

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

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

    @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.Posts: 12,822Member

    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 Posts: 604Member, PRO

    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.Posts: 12,822Member
    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 Posts: 644Member

    AaaaaaaAAAaa

  • Player_EPlayer_E Posts: 604Member, PRO
    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 Posts: 31Member, PRO

    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 Posts: 11,490Member, Sous Chef, PRO, Senior Sous-Chef

    @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 Posts: 31Member, PRO

    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 Posts: 31Member, PRO

    By the way it is applied to both actors.

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

    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 Posts: 31Member, PRO
    edited November 1

    ( 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 Posts: 11,490Member, Sous Chef, PRO, Senior Sous-Chef

    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

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

    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.