move in fixed increment?

DookiDooki Member Posts: 247
edited November -1 in Working with GS (Mac)
Hi there,

I'm working on a top view game. I want my actor(cricket) is 10x10. I want it to be able to move (hop) twice it's size ever time I click in a direction. What attribute would I use? thanks!

-Dooki

Comments

  • iDeveloperziDeveloperz Member Posts: 1,169
    Accelerate. going 45 degrees. You will also need gravity and make the ground unmovable. On the movement or physics tab. :)
  • DookiDooki Member Posts: 247
    Thanks for the reply but wouldn't I make a rule with 'move?" In essence I need the actor to "snap" a set distance with every click. From a top view I need it the actor to "hop" when moved.
    When I applied accelerate or move the actor moves as long as I hold down the mouse. I need the actor to move only a certain amount/value.

    Gravity: Since this is a top view game do need gravity?
    Thanks again!
    -Dooki
  • firemaplegamesfiremaplegames Member Posts: 3,211
    Use something like this, in the cricket Actor:

    Rule
    When Mouse is Down
    -----Change Attribute: self.Position.Y To: self.Position.Y + 20
  • DookiDooki Member Posts: 247
    Wow! this works. It "snaps" per click. However, I need to move in other directions. I tried copying the rule for other directions but no luck. Or course adding a "-20" to position.Y nullifies the movement. Likewise, adding a +20 to the Position.X makes the actor move at 45*.
    Thoughts?

    -Dooki
  • firemaplegamesfiremaplegames Member Posts: 3,211
    Well, you will need to account for the other directions with Rules.

    How many directions can the cricket move? 4?

    Let's say it is 4: Up, Down, Left and Right.

    So if you tap above the cricket, it will move up, if you tap below the cricket, it will move down, etc.

    In that case, imagine a giant invisible 'X' placed on the screen, with the center of the 'X' on the cricket.

    You now need to determine in which quadrant of the 'X' your Touch is located...

    Does that make sense?

    So in relation to the cricket:
    if the touch is between 45° and 135°, you want the cricket to move up.
    if the touch is between 135° and 225°, you want the cricket to move left.
    if the touch is between 225° and 315°, you want the cricket to move down.
    if the touch is between 315° and 45°, you want the cricket to move right.

    To find the angle of the Touch, use VectorToAngle.

    Create a new integer attribute in the cricket called 'myTouchAngle'.

    Then your Rules in the cricket actor will need to look like this:

    Rule
    When Mouse is Down
    -----Change Attribute self.myTouchAngle To: vectorToAngle(self.Position.X-game.Mouse.X,self.Position.Y-game.Mouse.Y)
    -----Rule
    -----All
    -----When self.myTouchAngle >= 45
    -----When self.myTouchAngle < 135
    ----------Change Attribute: self.Position.Y To: self.Position.Y + 20
    -----Rule
    -----All
    -----When self.myTouchAngle >= 135
    -----When self.myTouchAngle < 225
    ----------Change Attribute: self.Position.X To: self.Position.X - 20
    -----Rule
    -----All
    -----When self.myTouchAngle >= 225
    -----When self.myTouchAngle < 315
    ----------Change Attribute: self.Position.Y To: self.Position.Y - 20
    -----Rule
    -----All
    -----When self.myTouchAngle >= 315
    -----When self.myTouchAngle < 45
    ----------Change Attribute: self.Position.X To: self.Position.X + 20

    I hope this helps!
    More importantly, I hope you can follow and understand what I did.

    Joe
  • SingleSparqSingleSparq Member Posts: 1,339
    Joe - when are you writing a Game Salad book? Thats good solid info going into my scrapbook. Easy to read and understand - Thanks you for taking the time to write it up.
  • DookiDooki Member Posts: 247
    Thanks Joe! Macview is right, you explain things very well.
    The visual of an "X" is correct. I had to read your rules a couple of times but I get it now. You may not need to know C++ for this but it does take some brain juice to get the hang of this!

    Question though:
    - I get the four rules for each quad, but is the very first rule in the list a separate rule or are the subsequent four rules within that first rule? Thanks!

    -Dooki
  • DookiDooki Member Posts: 247
    Oh, and I am not sure how to get ">="
    I can't see the option for both. I thought maybe you added the "=" in with the numerical value but that didn't work either.

    -Dooki
  • iDeveloperziDeveloperz Member Posts: 1,169
    it is the > with the line under it.

    :)
  • DookiDooki Member Posts: 247
    oops.
  • DookiDooki Member Posts: 247
    Wow OK, I have the rules in but no movement at all. I was not clear if the 4 quad rules were under the first rule you mentioned or not. I've tried them separate and together and either way I have not movement. Do I need to set something in physics?

    Also, I'd like the actor to jump in the direction where the mouse clicks (or where I touch on the screen) so would I still use when mouse button is down OR when touch is pressed?

    Thanks a whole bunch!

    -Dooki
  • firemaplegamesfiremaplegames Member Posts: 3,211
    Oops! My bad. Apparently in this case the vectorToAngle function was returning a degree between -180 and 180 as opposed to 0 to 360.

    So I added a %360 to the vectorToAngle calculation. And I also switched the order of the operands, so instead of self.Position.X-game.Mouse.X it's game.Mouse.X-self.Position.X.

    That will bring it back to 0-360.

    So the logic is correct, but the angles and signs need to change:

    Create a new integer attribute in the cricket called 'myTouchAngle'.

    Then your Rules in the cricket actor will need to look like this:

    Rule
    When Mouse is Down
    -----Change Attribute self.myTouchAngle To: vectorToAngle(game.Mouse.X-self.Position.X,game.Mouse.Y-self.Position.Y)%360
    -----Rule
    -----All
    -----When self.myTouchAngle >= 45
    -----When self.myTouchAngle < 135
    ----------Change Attribute: self.Position.Y To: self.Position.Y + 20
    -----Rule
    -----All
    -----When self.myTouchAngle >= 135
    -----When self.myTouchAngle < 225
    ----------Change Attribute: self.Position.X To: self.Position.X - 20
    -----Rule
    -----All
    -----When self.myTouchAngle >= 225
    -----When self.myTouchAngle < 315
    ----------Change Attribute: self.Position.Y To: self.Position.Y - 20
    -----Rule
    -----ANY <----------------------------------------Be aware of this as well!
    -----When self.myTouchAngle >= 315
    -----When self.myTouchAngle < 45
    ----------Change Attribute: self.Position.X To: self.Position.X + 20

    So you will have one Rule, with a Change Attribute and 4 other Rules nested within it.

    In this case I would use When Mouse is Down - it translates to Touch on a device, but only allows one touch at a time.

    That should do it!
  • DookiDooki Member Posts: 247
    Thanks again Joe!

    OK, I have my actor scooting around like the old frogger game. The problem now is that when I click up the actor moves down. When I click on the right, the actor goes left. What am I doing wrong now?

    Mahalo.

    Dooki
  • firemaplegamesfiremaplegames Member Posts: 3,211
    I'm not sure. Is your Actor rotated at all?
  • DookiDooki Member Posts: 247
    Ooops, didn't see your reply until now.

    No, my actor doesn't seem to be rotating.

    Thanks!

    Dooki
Sign In or Register to comment.