Tap to Move like in Star Daze HD?

11clock11clock Member Posts: 450
edited November -1 in Working with GS (Mac)
I'd like to know how to do the control scheme that Star Daze HD did, but also being able to change to go to another position in mid-movement. How do you do this?

Comments

  • JamieOneilJamieOneil Member Posts: 877
    Very Simple.

    -Create a rule - When Touch is outside-
    -Change attribute - self.position.x to mouse.position.x-
    -Change attribute - self.position.y to mouse.position.y-

    If you need anymore help just ask.

    JamieOneil
  • RedlerTechRedlerTech Member Posts: 1,583
    JamieOneil said:
    Very Simple.

    -Create a rule - When Touch is outside-
    -Change attribute - self.position.x to mouse.position.x-
    -Change attribute - self.position.y to mouse.position.y-

    NO? You would need to do something but interpolate, but not interpolate as it cannot be interrupted.
  • tenrdrmertenrdrmer Member, Sous Chef, Senior Sous-Chef Posts: 9,934
    NextGen said:
    NO? You would need to do something but interpolate, but not interpolate as it cannot be interrupted.

    I'll bet you $100 it Can be.

    Check out my demos page There is a specific Cancel interpolate demo and a scene preview that uses interpolate for the preview but cancels it back to the the beginning.
    JamieOneil said:
    Very Simple.

    -Create a rule - When Touch is outside-
    -Change attribute - self.position.x to mouse.position.x-
    -Change attribute - self.position.y to mouse.position.y-

    If you need anymore help just ask.

    JamieOneil

    As for this. It pains me to say NextGen is correct in one thing. the Change attribute will not give you the effect of a movement. you will need to use move to or interpolate if you want it to move to a point and stop.

    Good luck
  • 11clock11clock Member Posts: 450
    There is a problem with using Interpolate. If you tap far away, the player will move very fast. However, if you tap a short distance away from the player, it will move slowly. This is a problem, especially in a dodging game.
  • tenrdrmertenrdrmer Member, Sous Chef, Senior Sous-Chef Posts: 9,934
    Well thats where you have to use math. And work out an expression that will base the time frame on the magnitude between your mouse position and actor.

    ___________________________________________________________________________________
    TEMPLATES AND PROJECT HELP BY TENRDRMER. CLICK HERE!!!

    AppSolute Entertainment on Facebook
    AppSolute Entertainment on iTunes
  • RedlerTechRedlerTech Member Posts: 1,583
    tenrdrmer said:
    Well thats where you have to use math. And work out an expression that will base the time frame on the magnitude between you mouse position and actor.

    Exactly
  • scitunesscitunes Member, Sous Chef Posts: 4,047
    ORBZ has a cool demo for shooting a projectile to a certain point. You can use the same idea and just add touch rules instead of spawning.

    Check it out - it's genius in its simplicity
  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    When mouse button down and self.IAmMoving is false
    --Change Attribute self.TargetX = mouse.Position.X
    --Change Attribute self TargetY = mouse.Position.Y
    --Change Attribute self.IAmMoving = true

    (Make sure you have an attribute that contains your pixels/second move rate and one that contains the time it should take to move. i.e. self.MoveRate and self.MoveTime)

    If self.Postion.X ≠ self.TargetX and self.Position.Y ≠ self.TargetY
    --Change Attribute self.MoveTime = magnitude(self.Position.X-self.TargetX, self.Position.Y - self.TargetY)/self.MoveRate
    --Interpolate self.Position.X to self.TargetX for self.MoveTime seconds
    --Interpolate self.Position.Y to self.TargetY for self.MoveTime seconds

    If self.Postion.X = self.TargetX and self.Position.Y = self.TargetY
    --Change Attribute self.IAmMoving = false
  • RedlerTechRedlerTech Member Posts: 1,583
    Great to see the head chefs helping out :D

    Matt
  • calvin9403calvin9403 Member Posts: 3,186
    tenrdrmer said:
    I'll bet you $100 it Can be.

    Check out my demos page There is a specific Cancel interpolate demo and a scene preview that uses interpolate for the preview but cancels it back to the the beginning.

    As for this. It pains me to say NextGen is correct in one thing. the Change attribute will not give you the effect of a movement. you will need to use move to or interpolate if you want it to move to a point and stop.

    Good luck

    lol
  • calvin9403calvin9403 Member Posts: 3,186
    someone delete my post?
  • 11clock11clock Member Posts: 450
    CodeMonkey said:
    When mouse button down and self.IAmMoving is false
    --Change Attribute self.TargetX = mouse.Position.X
    --Change Attribute self TargetY = mouse.Position.Y
    --Change Attribute self.IAmMoving = true

    (Make sure you have an attribute that contains your pixels/second move rate and one that contains the time it should take to move. i.e. self.MoveRate and self.MoveTime)

    If self.Postion.X ≠ self.TargetX and self.Position.Y ≠ self.TargetY
    --Change Attribute self.MoveTime = magnitude(self.Position.X-self.TargetX, self.Position.Y - self.TargetY)/self.MoveRate
    --Interpolate self.Position.X to self.TargetX for self.MoveTime seconds
    --Interpolate self.Position.Y to self.TargetY for self.MoveTime seconds

    If self.Postion.X = self.TargetX and self.Position.Y = self.TargetY
    --Change Attribute self.IAmMoving = false

    I'm trying this, but it's very, very bugged. Sometimes the object flashes, sometimes it stops responding, and sometimes it teleports. Also, at the start of the game it moves to the bottom left.

    The object moves faster when it goes diagonally, too.
  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    It is moving to the bottom left because your initial targetX and targetY values are (0,0).

    At the top of the behaviors list of the actor, just add change attribute behaviors to set TargetX and TargetY to the position of that actor.
  • MarkOnTheIronMarkOnTheIron Member Posts: 1,447
    I had the same problem on Zombie Pond, I wanted the dragonflies to use interpolate (because "move to" was insanely buggy) but I wanted them to move realistically.

    Here's what I did:

    You will need 4 self attributes (the ones you add on the actor prototype): NewX, NewY, iAmMoving, howMuchTime.

    When self.iAmMoving is false
    --When mouse button is down
    ----Change Attribute self.NewX to mouse.PositionX
    ----Change Attribute self.NewY to mouse.PositionY
    ----Timer after 0.1 seconds
    ------Change Attribute self.iAmMoving to true
    ------Change Attribute self.howMuchTime to max(0.1,((floor((magnitude(self.NewX-self.PositionX,self.NewY-self.PositionY))/50))/10))
    Otherwise
    --Interpolate self.Position.X to self.NewX for self.howMuchTime
    --Interpolate self.Position.Y to self.NewY for self.howMuchTime
    --Change Attribute self.Rotation to vectortoangle(self.NewX-self.PositionX,self.NewY-self.PositionY) (this is a little addendum to make your actor to face towards the direction he is moving)
    --Timer after self.howMuchTime seconds
    ----Change Attribute self.iAmMoving to false

    ________________________________
    【ツ】iPhone Icon Pack 【ツ】 - 【ツ】Graphic Pack【ツ】
    Free GS demo: High score simple and advanced; Game Center; App Rating System
  • 11clock11clock Member Posts: 450
    MarkOnTheIron said:
    I had the same problem on Zombie Pond, I wanted the dragonflies to use interpolate (because "move to" was insanely buggy) but I wanted them to move realistically.

    Here's what I did:

    You will need 4 self attributes (the ones you add on the actor prototype): NewX, NewY, iAmMoving, howMuchTime.

    When self.iAmMoving is false
    --When mouse button is down
    ----Change Attribute self.NewX to mouse.PositionX
    ----Change Attribute self.NewY to mouse.PositionY
    ----Timer after 0.1 seconds
    ------Change Attribute self.iAmMoving to true
    ------Change Attribute self.howMuchTime to max(0.1,((floor((magnitude(self.NewX-self.PositionX,self.NewY-self.PositionY))/50))/10))
    Otherwise
    --Interpolate self.Position.X to self.NewX for self.howMuchTime
    --Interpolate self.Position.Y to self.NewY for self.howMuchTime
    --Change Attribute self.Rotation to vectortoangle(self.NewX-self.PositionX,self.NewY-self.PositionY) (this is a little addendum to make your actor to face towards the direction he is moving)
    --Timer after self.howMuchTime seconds
    ----Change Attribute self.iAmMoving to false

    ________________________________
    【ツ】iPhone Icon Pack 【ツ】 - 【ツ】Graphic Pack【ツ】
    Free GS demo: High score simple and advanced; Game Center; App Rating System

    That doesn't work either. I click somewhere and half the time the object doesn't respond and the other half of the time it just vanishes. Once it did move, but it vanished afterwords.

    Want me to send the project file?
  • 11clock11clock Member Posts: 450
    I finally solved the problem. The problem is that max(0.1,((floor((magnitude(self.NewX-self.PositionX,self.NewY-self.PositionY))/50))/10)) does not work as expected and is probably a bug. Instead of using Interpolate I am using Change Velocity. I used the method in the topic below.

    http://gamesalad.com/forums/topic.php?id=16441

    Works perfectly!

    EDIT: There is a bug with the method mentioned above. When you click on the object, it will just fly off screen. You can fix this by placing a rule so that when touch is pressed (NOT if mouse button is down), set velocity to 0.
Sign In or Register to comment.