8 Way Controller - help needed

BagzliBagzli Member, PRO Posts: 48
edited April 2015 in Working with GS (PC)

Hello,

I have created an 8 way controller following a guide I found on youtube located here:

I've been trying to wrap my head around how it works and I've had some difficulties fully understanding the logic as I need to make a change on the controller. Bellow I will paste what attributes and objects I am using. The way it currently works is if I tap to the left of the inner box, my hero will start moving left immediately and for the game I am developing that causes a big problem. What I want to do is when I tap on the screen, that to become my initial position and then once I start dragging, then it will start moving my hero. Upon releasing, the joystick will then reset to its original position. If anyone can think of a way to alter this code and help me achieve this, it would be really helpful! I have named the attributes exactly as they are in the video.

Controller:

Game Attributes
    BG_Initial X - 0 - Real
    BG_Initial Y - 0 - Real
    BG_Radius - 0 - Real
    TC X - 0 - Real
    TC Y - 0 - Real

Object BG (This is the background of the controller, the big circle in the video)
    Group Initial
        Change Attribute
            game.BG_Initial X to self.position.x
        Change Attribute
            game.BG_Initial Y to self.position.y
        Change Attribute
            game.BG_Radius to self.size.width/2



    Object Controller (this is the small circle that gives the illusion of the controller inside the big circle)
    Group Move
        Constrain Attribute
            self.position.x to game.BG_Initial X + min(game.BG_Radius, magnitude(game.TC X - game.BG_Initial X, game.TC Y - game.BG_Initial Y))*cos(vectorToAngle(game.TC X - game.BG_Initial X, game.TC Y - game.BG_Initial Y))
        Constrain Attribute
            self.position.y to game.BG_Initial Y + min(game.BG_Radius, magnitude(game.TC X - game.BG_Initial X, game.TC Y - game.BG_Initial Y))*sin(vectorToAngle(game.TC X - game.BG_Initial X, game.TC Y - game.BG_Initial Y))




      Object Touch Controller (This is the invisible box that user taps and sits on top of two circles)
    Rule Touch
        When All of the following happening
            touch is inside
        do
            Constrain Attribute
                self.position.x to game.Touches.Touch 1.x
            Constrain Attribute
                self.position.y to game.Touches Touch 1.y
        else
            Constrain Attribute
                self.position.x to game.BG_Initial X
            Constrain Attribute
                self.position.y to game.BG_Initial Y
    Group TC Position
        Constrain Attribute
            game.TC X to self.position.x
        Constrain Attribute
            game.TC Y to self.position.y



Object Hero
    Group Move
        Move
            move in direction: vectorToAngle(game.TC X - game.BG_Initial X, game.TC Y - game.BG_Initial Y)
            relative to scene in a(n) additive way
            at speed of: magnitude(game.TC X - game.BG_Initial X, game.TC Y - game.BG_Initial Y)

Comments

Sign In or Register to comment.