360 image rotation with joystick

LordTarantorLordTarantor Member, PRO Posts: 890
edited November -1 in Working with GS (Mac)
Hello everybody:
I am using the codemonkey's joystick but I dont know how to make the player change images if he is north or south, left or right. Can somebody help me with this?
I used before and I was able to change image if it was moving right or left but it is not working the same way if I add up or down.

Comments

  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    If you use vectorToAngle(x,y) then you have an angle at which the joystick control is relative to the base. Using that angle, you can determine which is the best set of images to use.

    For example, if the angle is between 45 and 135, then you can use images facing up.
    If the angle is between 135 and 225, the image faces left. etc...
  • BSideGamesBSideGames Member Posts: 392
    If game.angle is 90 change image to (your new image) for exact up
    if game.angle is -90 change image to (your new image) for exact down

    the joystick is tricky because the number is always changing i use equal or less/greater than with some numbers

    use a debug text game.angle to watch the angle number change in real time.
    It will help you pick the numbers you want for positions of joystick
  • BSideGamesBSideGames Member Posts: 392
    I almost beat codemonkey... damn
  • LordTarantorLordTarantor Member, PRO Posts: 890
    Thanks Guys for answering.
    What I was doing is that if game.stick1grabbed is true
    Rule:
    Attribute self.MotionLinear velocityX is >or= to vectorto angle 131,225 for right and so on for the rest.
    But its not working. Can you tell me what I am doing wrong?
    Thanks
  • LordTarantorLordTarantor Member, PRO Posts: 890
    I just try changing everything that comes to my mind but it still moves crazy...
  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    Let's first learn what vectorToAngle does.

    It is a function that takes an X and Y coordinate and gives the angle that it creates between 0 degrees and the line it makes from that point to the origin(0,0).

    So if you want to find the angle using 2 coordinates you would use vectorToAngle(x1-x2,y1-y2).

    In this case, you would not use the linear velocity to determine which image to use.

    You would need to do something like

    Rule: If ALL
    45< vectorToAngle(x1-x2,y1-y2)
    135>vectorToAngle(x1-x2,y1-y2)

    since you are always using vectorToAngle(x1-x2,y1-y2) you may want to use an attribute that is constrained to that value.
  • dotsonj23dotsonj23 Member Posts: 316
    CodeMonkey said:
    Let's first learn what vectorToAngle does.

    It is a function that takes an X and Y coordinate and gives the angle that it creates between 0 degrees and the line it makes from that point to the origin(0,0).

    So if you want to find the angle using 2 coordinates you would use vectorToAngle(x1-x2,y1-y2).

    In this case, you would not use the linear velocity to determine which image to use.

    You would need to do something like

    Rule: If ALL
    45< vectorToAngle(x1-x2,y1-y2)
    135>vectorToAngle(x1-x2,y1-y2)

    since you are always using vectorToAngle(x1-x2,y1-y2) you may want to use an attribute that is constrained to that value.

    Nice explanation. FYI... I finally figured out how to convert your demo for one moving joystick so that I could also have another joystick or d-pad without it screwing up the moving joystick. I have it working on my I-pad. I am pretty sure I can now do two moving joysticks at the same time with some minor modifications. This took me forever and I should have probably just asked but I find sometimes that I learn more when I just mess around with it until I get it to work.
  • LordTarantorLordTarantor Member, PRO Posts: 890
    Oh, I am sorry CodeMonkey but I just don't understand. I ll totally understand if you get frustrated with me. This is new to me.
    How do I put the 45 or 135 in the rule?
    What would be the numbers to use in the x1-x2,y1-y2?
    Sorry again.
  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    Actually, you don't need to be too confused about it. If you are using my demo, there are game attributes called Angle and Angle2. These should be calculated by the joystick handles.

    So your rule would only need
    If attribute game.Angle >45
    AND attribute game.Angle < 135

    x1,y1 and x2,y2 are the coordinates of the Stick actor and the corresponding Base actor.
  • dotsonj23dotsonj23 Member Posts: 316
    dotsonj23 said:
    Nice explanation. FYI... I finally figured out how to convert your demo for one moving joystick so that I could also have another joystick or d-pad without it screwing up the moving joystick. I have it working on my I-pad. I am pretty sure I can now do two moving joysticks at the same time with some minor modifications. This took me forever and I should have probably just asked but I find sometimes that I learn more when I just mess around with it until I get it to work.

    Figured if I talked about it I should post it. So here it is.

    http://gamesalad.com/game/play/91997
  • LordTarantorLordTarantor Member, PRO Posts: 890
    Its starting to move better but its not facing the right direction unless its moving up. Here it is what I am doing, step by step.
    In the player:
    Move:
    Direction game.Angle relative to actor Move Type: additive
    speed: 70*game.DistanceFrom Center/game.BaseRadius

    Rule-(Direction)
    Whee all
    attribute game.stickgrabbed is true
    Rule
    when all
    attribute: game.Angle>131
    attribute: game.Angle<225
    Animate (right pics)
    Otherwise:

    Rule
    when all
    attribute: game.Angle>226
    attribute: game.Angle<315
    Animate (down pics)

    Rule
    when all
    attribute: game.Angle>316
    attribute: game.Angle<45
    Animate (left pics)

    Rule
    when all
    attribute: game.Angle>46
    attribute: game.Angle<130
    Animate (up pics)

    So that is what I am doing. The up its ok, If I go left it shows me the animation of the right and if I go down or right, no animation.
    Thanks for your patience CodeMonkey.
Sign In or Register to comment.