playMaker

Author Topic: Twin Stick Shooter Mobile Joystick Help  (Read 6167 times)

OddButAwesome

  • Playmaker Newbie
  • *
  • Posts: 49
    • Odd but Awesome Apps on Playstore
Twin Stick Shooter Mobile Joystick Help
« on: October 27, 2015, 11:53:51 AM »
Hi all,

Does anyone know of a tutorial for the above subject? A real slow step by step one for a new person like myself.

I have my player moving with the left stick all good but the rotation from the right stick is not working at all. I have tried advice from http://hutonggames.com/playmakerforum/index.php?topic=6559.msg31999#msg31999  but I fear my newness is not helping.

I am using the CrossPlatformInput prefab - MobileSingleStickControl for both sticks. Attached is the c# for the left stick (movement) it has been adjusted to fix the snapping bug, so it's good.

Thank you.

OddButAwesome

  • Playmaker Newbie
  • *
  • Posts: 49
    • Odd but Awesome Apps on Playstore
Re: Twin Stick Shooter Mobile Joystick Help
« Reply #1 on: October 29, 2015, 01:11:30 AM »
Trying to integrate this package.

http://hutonggames.com/playmakerforum/index.php?topic=2476.msg11131#msg11131

Unity 5.2.0f3 64bit with Playmaker1.7.8.3p2. I create a new empty project. Import PM. Import CrossplatformInput. Import the joystick package from link above. Add Canvas (auto adds Event System). Drag the Controls prefab onto the canvas. Project comes up with errors and won't open properly after I close.

Please see screen shot for errors.

Am I missing something?


KellyRay

  • Full Member
  • ***
  • Posts: 170
Re: Twin Stick Shooter Mobile Joystick Help
« Reply #2 on: October 29, 2015, 10:36:46 AM »
I'm unfamiliar with the joystick package.

However, I've created some actions for the cross platform input assets.

Check them out!

http://hutonggames.com/playmakerforum/index.php?topic=11224.0

OddButAwesome

  • Playmaker Newbie
  • *
  • Posts: 49
    • Odd but Awesome Apps on Playstore
Re: Twin Stick Shooter Mobile Joystick Help
« Reply #3 on: October 29, 2015, 08:53:10 PM »
Thanks KellyRay! :)

I will check them out.

OddButAwesome

  • Playmaker Newbie
  • *
  • Posts: 49
    • Odd but Awesome Apps on Playstore
Re: Twin Stick Shooter Mobile Joystick Help
« Reply #4 on: October 29, 2015, 10:46:51 PM »
This is the furthest I have got with this. The right joystick now rotates the player ship (Thank you @KellyRay for your CrossPlatform package) correctly but snaps to the compass points (NSEW).

While I can adjust the speed of snapping this doesn't allow the player to (for example) shoot at a 45 degree angle unless they flick between Vertical/Horizontal.

The FSM.png is attached to my R-Joystick. HorizontalR / VerticalR are in the project settings input.

I feel I am going about this in a clumsy manner and the correct method is just beyond my sight. Still learning. Frustrating but fun...or is that the other way around... :)

Any advice on how to get all degrees of control?

Thank you.

KellyRay

  • Full Member
  • ***
  • Posts: 170
Re: Twin Stick Shooter Mobile Joystick Help
« Reply #5 on: October 30, 2015, 12:58:49 PM »
So the problem you are having is that you want the ship to rotate around in 360 degrees at any given point and not snap to the compass directions?

This will require a bit of math. What you want to do is store horizontal and vertical axis as float variables using the get axis action and plug them into an equation that looks like this:

var angleRadians=Mathf.Atan2(Vertical_axis, Horizontal_axis);

var angleDegrees = angleRadians * Mathf.RadToDeg;

And then you would set your rotation value to be equal to angleDegrees every frame.

OddButAwesome

  • Playmaker Newbie
  • *
  • Posts: 49
    • Odd but Awesome Apps on Playstore
Re: Twin Stick Shooter Mobile Joystick Help
« Reply #6 on: November 03, 2015, 12:37:32 PM »
Thank you for your reply @KellyRay.

My ship is still not rotating. This is my C# script:

-----------------------------------------
using UnityEngine;
using System.Collections;
using UnityStandardAssets.CrossPlatformInput;

public class RotateShoot_2 : MonoBehaviour
   
{
   // Update is called once per frame
   void Update ()
   {
      
      Vector3 vNewInput = new Vector3(CrossPlatformInputManager.GetAxis("HorizontalR"), CrossPlatformInputManager.GetAxis("VerticalR"), 0.0f);

      
   }

   void rotatePlayer ()
   {   
      var angleRadians = Mathf.Atan2(CrossPlatformInputManager.GetAxis("HorizontalR"), CrossPlatformInputManager.GetAxis("VerticalR"));

      var angleDegrees = angleRadians * Mathf.Rad2Deg;

      transform.rotation = Quaternion.Euler(0, 0, angleDegrees);

   }
}
-----------------------------------------

I know the right joystick is working as when I add a FSM with Cross Platform Get Axis with HorizontalR and VerticalR, I get numbers from the debug field (i.e. 0 at start and changes from -.99 to +.99 when I move the right joystick).

The script is dropped on the Player. I have removed any rotation constraints except for Z-Position. Project settings Input has the HorizontalR and VerticalR set to Joystick 2.

I am tearing out what little (read: none) hair I have left over this challenge. I just can't see what I am doing wrong. I have looked at youtube tutes as well as various forums and QnA sites.

Any help would be most appreciated. Thanks.


KellyRay

  • Full Member
  • ***
  • Posts: 170
Re: Twin Stick Shooter Mobile Joystick Help
« Reply #7 on: November 03, 2015, 12:53:53 PM »
You never call the void rotatePlayer() in the update function so that method is not doing anything.

try adding this line

rotatePlayer();

to the update part of the script.

KellyRay

  • Full Member
  • ***
  • Posts: 170
Re: Twin Stick Shooter Mobile Joystick Help
« Reply #8 on: November 03, 2015, 01:25:56 PM »
You could also take the logic out of the rotatePlayer() and stick it in the update function.

OddButAwesome

  • Playmaker Newbie
  • *
  • Posts: 49
    • Odd but Awesome Apps on Playstore
Re: Twin Stick Shooter Mobile Joystick Help
« Reply #9 on: November 04, 2015, 06:39:34 AM »
Thank you so much! I am still learning and am grateful for your patience.

Your advice helped me with this and another issue.

As mentioned I searched various links and tutes. I found this worked.
I did have to change some lines. I have attached the scripts in the hopes it will help others. Please keep in mind I mostly fumbled my way through with the help of some fine & knowledgeable people. So what worked for me may not work for other new peeps :)


P.S. I should mention - upon lifting my finger from joy2 the ship snaps to point north. This is another issue I will be working out next.

P.P.S. EDIT: OK so... maybe I jumped the gun a abit. It works fine in Unity in test mode but upon export to my phone the 2nd joy doesnt work... damn. will report later.
« Last Edit: November 04, 2015, 06:53:08 AM by OddButAwesome »

KellyRay

  • Full Member
  • ***
  • Posts: 170
Re: Twin Stick Shooter Mobile Joystick Help
« Reply #10 on: November 04, 2015, 11:58:37 AM »
My best guess on the always pointing north is that when you don't have your finger on the joystick the axis values become 0. So its calculating every by 0 making it zero degrees every frame.

You could add a button component to joystick and do an

if (CrossPlatformInputManager.GetButton)

And then put your rotating logic in that bracket.

I'm not much of a scripter which is why I enjoy playmaker :D But I think that would make the most sense for why it turns to 0 every frame.