Touch and Drag question

AfterBurnettAfterBurnett Member Posts: 3,474
edited November -1 in Working with GS (Mac)
Hi guys,

The game I'm working on requires a "touch and drag" control method. I used this for Max Vector but what I need for this game needs to have a limited speed. Kinf of like the game "Racer" (which, by the way is absolutely brilliant - check it out!).

For example, I want to be able to drag my finger and the object follows but at a set maximum speed... it shouldn't "keep up" with the player's finger. I also don't want it to jump or warp to wherever the player places their finger.

How would I go about doing this?

Cheers :)
«1

Comments

  • AfterBurnettAfterBurnett Member Posts: 3,474
    Anyone?

    I've tried it with "move to" and it works perfectly, very smooth... only when it reaches its destination, you have to remove your finger and press down again to start the sequence off again. I need it so that it's constantly following your finger...
  • AfterBurnettAfterBurnett Member Posts: 3,474
    Anyone? HEEEEEELP PLEEEEAAAASEEE :-P
  • dmilinovichiiidmilinovichiii Member Posts: 620
    POLYGAMe said:
    Anyone?

    I've tried it with "move to" and it works perfectly, very smooth... only when it reaches its destination, you have to remove your finger and press down again to start the sequence off again. I need it so that it's constantly following your finger...

    Is run to completion checked?
  • scitunesscitunes Member, Sous Chef Posts: 4,047
    use accelerate towards. Then for the coordinates use touch1x + camera.originX and touch1y+camera.originY.

    Wrap it in a when touch is pressed rule.

    Obviously this will force you to unlock an instance to get to the scene camera.

    I took this from the wiki page about how to have an actor follow the mouse and changed it to the accelerate toward to do what you are talking about.

    I would also then set the max speed. I like a max speed around 300 and a high acceleration to make the angle changes responsive. You could probably work out a Touch Racing system by using magnitude between the player and the touch coordinates so that the farther away your finger is the faster it accelerates. Just a thought.
  • AfterBurnettAfterBurnett Member Posts: 3,474
    Yeah I tried with and without :(
  • dmilinovichiiidmilinovichiii Member Posts: 620
    Try this:
    Create a timer so that every 0.01 seconds, the actor moves to the touch x and y continuously.
    image
  • AfterBurnettAfterBurnett Member Posts: 3,474
    Mr.Rinoy said:
    Try this:
    Create a timer so that every 0.01 seconds, the actor moves to the touch x and y continuously.
    image

    Tried that too... horrible. WAY too jerky.
  • scitunesscitunes Member, Sous Chef Posts: 4,047
    Here's what I did, and it works fine.

    image

    hope it helps!
  • AfterBurnettAfterBurnett Member Posts: 3,474
    Cheers Scitunes, I'll try that. I had a muck around with accelerate towards and it kept "swinging". Also even when I used "if touch not pressed, change velocity to 0" it kept moving slightly...
  • AfterBurnettAfterBurnett Member Posts: 3,474
    With that method would I have the same problem with inertia? I found the object would overshoot the mark because of the acceleration rule.... hence the "swinging". It would try and correct, over shooting the mark in the other direction... kept on going. I think I invented perpetual motion!
  • scitunesscitunes Member, Sous Chef Posts: 4,047
    True, that will be a problem. What about using the above method, but put a change attribute in the otherwise of the touch is pressed rule to change the drag to a really high number. That may slow it way down. You could try that with a change linear.motion.X and Y to 0.

    I didn't realize you needed it to stop when you release when I suggested that approach.
  • AfterBurnettAfterBurnett Member Posts: 3,474
    Yeah, I'll try that. Thanks :)
  • BarkBarkCoBarkBarkCo Member Posts: 1,400
    Check out this demo. The speed at which the actor moves toward the mouse can be controlled by changing the duration in the interpolates...

    http://gamesalad.com/game/play/72498
  • AfterBurnettAfterBurnett Member Posts: 3,474
    I don't want it to move towards the mouse, I want it to move with the mouse, only with a limited speed... so you can't just thrash your finger left and right and have the object "stick" to it...

    Just like in Racer, you guide the car with your finger but it won't keep up if you move super fast (othrwise it would be unrealistic).
  • BarkBarkCoBarkBarkCo Member Posts: 1,400
    Link to racer? Google brings back way too much...
  • scitunesscitunes Member, Sous Chef Posts: 4,047
    What if you use my rule set in the image above but you wrap it in a rule that checks the magnitude of the car's distance from the touch and it only accelerates towards when that distance is greater than a certain number. So when it gets close to your finger it does not do that crazy dance around your finger tip thing. In the otherwise of that try the large drag and change linear motion thing that I suggested earlier.

    just a thought.
  • AfterBurnettAfterBurnett Member Posts: 3,474
    Yeah, sounds like that should work. I'll give it a go when I get home. No GS at work. LOL. Thanks heaps, I've not messed with magnitude before! All a learning curve, this GS thing :)
  • BarkBarkCoBarkBarkCo Member Posts: 1,400
    Found it:
  • scitunesscitunes Member, Sous Chef Posts: 4,047
    constrain self.DistanceFromFinger to magnitude(self.positionX-touch1X,self.posiitonY-touch1Y)

    Then Wrap the above rules in

    When self.DistanceFromFinger > 20 (or whatever feels right)

    OTHERWISE

    Change attribute linear drag to 2000
    Change attribute linear.motionX to 0
    Change attribute linear.motionY to 0

    Or put the otherwise changes in the otherwise of the When touch is pressed rule (or both!)

    Something like that
  • AfterBurnettAfterBurnett Member Posts: 3,474
    Hmmm... that doesn't seem to do anything...
  • AfterBurnettAfterBurnett Member Posts: 3,474
    Also, it seems drag is applied during the movement even when placed inside an "otherwise". I did read somewhere that physics attributes can't be changed in game...
  • scitunesscitunes Member, Sous Chef Posts: 4,047
    damn! I wonder if using drag like that used to work before they changed it to a physics setting as opposed to a behavior - I swear I used it once like that.
  • scitunesscitunes Member, Sous Chef Posts: 4,047
    The only thing I can think of would be a spawn and destroy approach (less than ideal).

    When you want it to stop it spawns a copy of itself and destroys itself.
  • BarkBarkCoBarkBarkCo Member Posts: 1,400
    scitunes said:
    constrain self.DistanceFromFinger to magnitude(self.positionX-touch1X,self.posiitonY-touch1Y)

    Then Wrap the above rules in

    When self.DistanceFromFinger > 20 (or whatever feels right)

    OTHERWISE

    Change attribute linear drag to 2000
    Change attribute linear.motionX to 0
    Change attribute linear.motionY to 0

    Or put the otherwise changes in the otherwise of the When touch is pressed rule (or both!)

    Something like that
    Since your using a CHANGE for the drag you will need to release the drag with a CHANGE to 0 in the THEN section of the rule.
  • scitunesscitunes Member, Sous Chef Posts: 4,047
    @Poly - I think I have a solution for stoping your racer. You do have dynamic control over max speed during game play. So you can use a change attribute behavior to set max speed to 0. Make sure you have max speed checked to begin with. Then in the rule that has the movement controls be sure to have another change attribute to change the max speed up to a higher number.

    I can't believe you didn't think of MAX speed!

    :)
  • quantumsheepquantumsheep Member Posts: 8,188
    scitunes said:

    I can't believe you didn't think of MAX speed!

    :)

    Ha! :D

    Dr. Sam Beckett never returned home...
    Twitter: https://twitter.com/Quantum_Sheep
    Web: https://quantumsheep.itch.io

  • AfterBurnettAfterBurnett Member Posts: 3,474
    Hahaha, I'll look into it! Girlfriend's day off today... I'm not allowed to spend all day in front of the computer :(
  • AfterBurnettAfterBurnett Member Posts: 3,474
    Okay, just tried it quickly. It works but only if you take your finger off the player actor. If you leave it on, it still "swings".
  • scitunesscitunes Member, Sous Chef Posts: 4,047
    You can't put it in a magnitude rule. So constrain self.DistanceFromFinger to magnitude(self.positionX-touch1x, self.positiony-touch1Y)

    Rule
    When self.distanceFromFinger is <5
    change attribtue maxspeed to 0
    OTHERWISE
    change maxspeed to 300(or whatever)

    does that work?
  • AfterBurnettAfterBurnett Member Posts: 3,474
    Yeah I had a quick go but I'll have a proper muck around later... uh oh.. she's coming... GOTTA RUN!!!!
Sign In or Register to comment.