GS v1.25.5 - Issues with Joystick / Aim functionality

(Note - this issue was pulled from a different thread and started as a new thread)

Ok - So I've been building a project using @Photics Dual Joystick Controller scheme / template in which data is extrapolated from touch-points generated when the player touches virtual joystick assets (a disc-shaped asset). The problem is, some of the data does not appear to be updating correctly - possibly due to the order in which my code is written or due to something new with how GS handles layers, etc.

As it is currently set up, there are three actors where the code is tied to in which the “Fire control” operates. The Joystick actor, a Turret actor (on a player vehicle), and the Bullet actors which are fired.

In the Joystick actor, the setup is straight-forward. I am extrapolating an AIM variable based on the vector in which the player is touching (and I calculate for up to 5 touch points should a player have all paws on the screen at once)

RULE – If When TOUCH is Inside
Change Attribute – game.joystick1touched = TRUE
RULE –
If game.touches.touch 1.X < self.Position.X + ( self.Size.Width /2)
and game.touches.touch 1.X > self.Position.X – ( self.Size.Width /2)
and game.touches.touch 1.Y < self.Position.Y + ( self.Size.Height /2)
and game.touches.touch 1.Y < self.Position.Y – ( self.Size.Height /2)
THEN Constrain Attribute game.AIM = vectorToAngle(game.Touches.Touch1X - self.Position.X , game.Touches.Touch1.Y - self.Position.Y)

OTHERWISE (I then repeat this rule for Touch.2 through Touch.5)

For the Turret actor, I am first constraining it’s position to the player’s vehicle, so it remains centered on the top, like a tank turret. Next I’m rotating the turret to the AIM variable when the Joystick is touched–

RULE –
If game.Joystick1touched = TRUE
THEN Rotate to Angle (angle = game.AIM) relative to SCENE, speed 900 (Run to completion / Stops not toggled)

Also, I’m running the code to fire the weapon –

RULE -
If game.joystick1touched = TRUE
and self.rotation = game.AIM
THEN Spawn Actor BULLET (layer – in front of actor, dir 0 relative to actor, position 0,0 relative to actor)
Play Sound (PewPew)

(I also include a Timer so that every 0.5 seconds, the THEN behaviors fire again – this is for players holding down on the stick and shooting is repeating)

Finally, for the bullet Actors, I have the following code:
Change Velocity – dir 0, relative to actor, speed 1000

(I also have several rules in which if the bullet hits different actor tags different things happen, from self-destroying when hitting boundary walls to spawning explosions, etc.)

In regards to Layers, I have the Joystick disc in the top layer with all HUD elements, as it is not scrollable. The player ship is in a lower layer, with the turret asset right above it, in the Player layer.

With this set-up, when I push the build to a device, touching the joystick disc will cause the turret to rotate, but not always to the angle I’m touching on the disc (e.g. I’m touching the bottom of the disc image and the turret points upwards at a 40-degree angle). The bullets will also spawn at the incorrect angle (often times pointed at the correct angle), but then zooming off at the angle the turret is pointed at. After holding down on the disc, the turret will spin to the correct angle after a second or so but if I move my finger on the turret (as if to aim at a moving target), sometimes the turret just spins wildly, firing bullets.

I’ve wrestled with this code in which I’ve used recycled bullets vs. spawned ones and the effect is the same.

What makes things totally bizarre is that this ONLY happens when I push the build to my device; never in Preview mode on the creator..

Any ideas?

-- J

Comments

  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922

    Gamesalad used to have a great controller package template. Not sure if it's still available. There was a great joystick controller in it.

  • KnightStarKnightStar Member Posts: 162

    Yeah, they did....and Darren & Wayne @UtopianGames generated a much better version as well.. I use both, but I wanted to go with the @Photics version since it didn't require a actors for each Touch..

    Again, I'm curious as to what changed in the code that causing this..

    At this point, I've rolled back to 1.24.42 to wrap this project up but it does make me wonder what might be going on under the hood for going back to 1.25.5..

  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922

    @KnightStar said:
    Yeah, they did....and Darren & Wayne @UtopianGames generated a much better version as well.. I use both, but I wanted to go with the @Photics version since it didn't require a actors for each Touch..

    Again, I'm curious as to what changed in the code that causing this..

    At this point, I've rolled back to 1.24.42 to wrap this project up but it does make me wonder what might be going on under the hood for going back to 1.25.5..

    Layer order I'm sure.

  • KnightStarKnightStar Member Posts: 162

    Layer order is as follows (all from top to bottom)

    • HUD Elements (Where joystick actor is located) - only layer not-scrollable
    • Explosions (all explosion anim assets)
    • Player Shots (all recycled Player Bullet actors)
    • Player (Turret actor where bullets emit, vehicle actor, particle actor)
    • All remaining asset in various layers bellow (e.g. enemies, level rules, backgrounds, etc...)

    It'd be interesting if Layering was an issue, tho, as players would not be able to have a code coming from a HUD-based element such as a virtual joystick being a problem..

    -- J

  • SocksSocks London, UK.Member Posts: 12,822

    If game.touches.touch 1.X < self.Position.X + ( self.Size.Width /2)
    and game.touches.touch 1.X > self.Position.X – ( self.Size.Width /2)
    and game.touches.touch 1.Y < self.Position.Y + ( self.Size.Height /2)
    and game.touches.touch 1.Y < self.Position.Y – ( self.Size.Height /2)

    . . . . . . . . . .

    Not sure what these conditions do, I'm assuming that the last condition should be '1.Y > self.Position.Y' rather than '1.Y < self.Position.Y' . . . . if so then these conditions describe anywhere on the screen, you can replace them all with 'when mouse button is down' ?

  • KnightStarKnightStar Member Posts: 162

    The game is a dual-stick shooter type game with other elements involved.

    I use the same code on both the player flight-directional stick as well as the gun stick (which what I'm having a problem with).. and yes, I think you found a typo vs. the actually code..

    game.touches.touch 1.Y < self.Position.Y – ( self.Size.Height /2)
    should be
    game.touches.touch 1.Y > self.Position.Y – ( self.Size.Height /2)

    On Left-stick, I'm pulling the data for heading and distance-from-center of the stick asset to provide acceleration.. Note, none of this is an issue - the problem lies with the Right-stick, in which I'm solely pulling the angle at which the player is touching on the stick actor and constraining it to an AIM variable. That aim variable is then used to rotate the gun turret on the player's ship and point the bullets in the direction that the gun is pointing..

  • SocksSocks London, UK.Member Posts: 12,822

    . . If game.touches.touch 1.X < self.Position.X + ( self.Size.Width /2)
    and game.touches.touch 1.X > self.Position.X – ( self.Size.Width /2)
    and game.touches.touch 1.Y < self.Position.Y + ( self.Size.Height /2)
    and game.touches.touch 1.Y > self.Position.Y – ( self.Size.Height /2)

    Are these conditions set to 'any' or 'all' ?

    If set to 'any' then these conditions serve no purpose as they collectively describe anywhere on the screen.

    If set to 'all' then the conditions can never be met (they can't all be true).

    Either way I'm a little confused as to what these conditions are trying to achieve ? Apologies if I'm being stupid, there might be some aspect to your project I've not taken into account.

  • KnightStarKnightStar Member Posts: 162

    Hey @Socks - yer not being stupid at all, this is an interesting problem we're trying to wrap our heads around..

    I guess the best way to explain it would be to show you the specific usage - first, see the description of the Joystick code used by @Photics here - https://photics.com/gamesalad-template-dual-controllers/

    Also, see the code in action (enclosed)

  • FrantoFranto Member Posts: 779

    I don't have time to test it right now, but have you tried putting the joystick layer at the bottom? The layers are read bottom to top, while actors top to bottom.

    A lot of stuff in my game was fixed by just moving the touch controls to the bottom {although now I gotta make a pseudo touch layer at the top, one that just have behaviors for lighting up when you touch it, while the actual touch actor is at the bottom covered up by other sprites.

  • SocksSocks London, UK.Member Posts: 12,822

    @KnightStar said:
    Also, see the code in action (enclosed)

    Unfortunately I've not got a copy of GS at the moment (poverty!), so I can't take a look at your example project . . . but I did read the description and it doesn't offer any further reasoning why those 4 conditions would serve any obvious purpose.

  • KnightStarKnightStar Member Posts: 162

    I don't have time to test it right now, but have you tried putting the joystick layer at the bottom? The layers are read bottom to top, while actors top to bottom.

    A lot of stuff in my game was fixed by just moving the touch controls to the bottom {although now I gotta make a pseudo touch layer at the top, one that just have behaviors for lighting up when you touch it, while the actual touch actor is at the bottom covered up by other sprites.

    I think we were on the same page, as I performed that test as well, by placing the joystick actor on a lower layer w/ ALPHA set at 0 and then creating a dummy asset to place over it in the HUD layer. Sadly, no luck..

    But thanks for thinking of it!!

    -- J

  • AtomikFuelAtomikFuel Member, PRO Posts: 6

    Using Photics method for touch to aim (Franto layering suggestion), attached is a "from scratch" version that does work in Device Previewer. Layering sounds like the issue, if you reorder the layers from how this example is stacked, random flickering and odd random aiming occurs.

    Tested GS1.25 in Device Preview on iPad2

  • IceboxIcebox Member Posts: 1,485
    edited May 2016

    @KnightStar Hey I played with your project the last hour and I think I found a temporary solution if you want, might not be the best one though, here is before and after

    Before

    After

    I added 2 game attributes distancefromcenter and Joystick2radius
    In joystick2 actor
    Constrained distancefromcenter to magnitude(positionx-game.fighterx,positiony -gamefightery)

    Changed attribute Joystick2radius to self.sizewidth/2

    In the Turret actor i deleted these 2 rules
    Rule1
    if game.joystick2 is true rotate to angle at angle game.aim speed of 1200
    Rule2
    attribute game.joystick2 is true and self.rotation = game.aim
    spawn 2 actors

    I tried to add 1200* game.distance/joystickradius in the speed of rotate to angle behavior but it didnt work unless i turned off the spawn rule , and i tried to reduce the speed it didnt work at all so i deleted them both

    Created 1 rule
    if game.joystick is true
    constrain attribute self.rotation to
    (game.Aim+90)+1200*(game.distancefromcenter/game.joystickradius)
    and spawn

    I didn't try it on device but the results are from the gs viewer, hope it works though.

    Edit : (project attached doesnt work well with movement on device )

  • IceboxIcebox Member Posts: 1,485

    ok turns out the speed was too high and the rotation had to be different to when its moving or not, I test it on my iphone 5 it kept rotating when i moved it, so i added a moving condition and reduced the speed when it moved + changed its angle a bit when its moving , i changed the speed of the bullet so that it matches the ship when it moves as well you can adjust everything , its all about numbers now i attached it here ( ignore the upper one and download this one)

    results from iphone 5s

  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    edited May 2016

    Yep with all the tightening of the software some of these old projects will need to rework. I'll have to see if I have the old Gamesalad joystick template.

  • IceboxIcebox Member Posts: 1,485
    edited May 2016

    It is available in the documentations along with other templates
    http://gamesalad.com/manuals

    What i personally do , i take parts of the gs official template and mix it with lost_oasis_games multi touch method . Works great if you have problems with spawning the touch like the template does.

  • KnightStarKnightStar Member Posts: 162

    Hey @Icebox -

    Thanks for looking into this. I'll crack that last project file open and see if I can find if
    that solves the problem!

Sign In or Register to comment.