News: Enjoy our Christmas offer 30% off on our latest package Tower Defense Level Kit http://u3d.as/m7h

  • October 18, 2018, 03:41:43 AM

Login with username, password and session length

Author Topic: Easy Joystick & input.getaxis  (Read 9581 times)

Offline ale

  • Newbie
  • *
  • Posts: 2
Easy Joystick & input.getaxis
« on: April 29, 2013, 03:51:24 PM »
Hello..
sorry for my bad-english..
I need to move a 3d-Animated Character in android with Accelerometer and/Or
Easy Joystic..
for accellerometer i use Input.GetAxis and then call animation.play etc.etc.

How can I use Easy Joystick for the same thing?
 thanx in advance..

Offline Nicolas

  • Administrator
  • Hero Member
  • *****
  • Posts: 792
Re: Easy Joystick & input.getaxis
« Reply #1 on: April 29, 2013, 04:08:29 PM »
Hi,

It's very easy.

1- Setup your joystick with Interaction = Include
2- Add a public variable MyJoystick type of EasyJoystick in your script
3- replace your Input.GetAxis by MyJoystick.JoystickAxis.x or MyJoystick.JoystickAxis.y
4- Drag & drop your joystick from hierarchy to inspector

Nicolas

Offline ale

  • Newbie
  • *
  • Posts: 2
Re: Easy Joystick & input.getaxis
« Reply #2 on: April 30, 2013, 10:43:04 AM »
Great !!! amazing!!!
Thanx

Offline Dev01

  • Newbie
  • *
  • Posts: 2
Re: Easy Joystick & input.getaxis
« Reply #3 on: January 17, 2014, 10:16:35 PM »
Can someone post an example if how to do this in JavaScript please.
I am not a programmer but this would solve a problem I'm having as well.

Offline Nicolas

  • Administrator
  • Hero Member
  • *****
  • Posts: 792
Re: Easy Joystick & input.getaxis
« Reply #4 on: January 17, 2014, 11:05:03 PM »
Hi Dev01,

What is your problem ?

Nicolas

Offline Dev01

  • Newbie
  • *
  • Posts: 2
Re: Easy Joystick & input.getaxis
« Reply #5 on: January 18, 2014, 10:43:23 AM »
I would like to replace my accelerometer input with easyjoystic as well. Unfortunately I know nothing of coding, I mostly cut an paste code that works so... I'm using JavaScript and would like an example of how to set a public variable etc like the post above but in JavaScript.
I would greatly appreciate it.
Thanks for the great product by the way!
I would never be able to script this kind of movement on a mobile joystick myself.
If you need me to send a copy of the script I'm using let me know.
Thanks in advance

Offline Nicolas

  • Administrator
  • Hero Member
  • *****
  • Posts: 792
Re: Easy Joystick & input.getaxis
« Reply #6 on: January 18, 2014, 12:41:14 PM »
Hi,

Yes, can you send me your script, it will be more simple

Nicolas

Offline Nicolas

  • Administrator
  • Hero Member
  • *****
  • Posts: 792
Re: Easy Joystick & input.getaxis
« Reply #7 on: January 21, 2014, 09:39:04 PM »
Hi,

I send you some modification for your script yesterday

Offline jbam

  • Newbie
  • *
  • Posts: 5
Re: Easy Joystick & input.getaxis
« Reply #8 on: January 27, 2014, 02:29:37 PM »
hello

sorry for my english but i'm french :) :)
Myjoystick interaction type is : include
and my code based on this post.
but don't work :'(

Code: [Select]
using UnityEngine;
using System.Collections;

public class deplacementougi : MonoBehaviour {
public EasyJoystick MyJoystick;

protected Animator animator;
public float DirectionDampTime = .50f;
public bool ApplyGravity = false;

void Start ()
{
animator = GetComponent<Animator>();
if(animator.layerCount >= 2)
animator.SetLayerWeight(1, 1);
}

    void Update ()
{
if (animator)
{
// deplacement clavier
float h = Input.GetAxis("Horizontal");
float v = Input.GetAxis("Vertical");

animator.SetFloat("Speed", h*h+v*v*100);
animator.SetFloat("Direction", h, DirectionDampTime, Time.deltaTime);

// deplacement joystick
float hj = MyJoystick.JoystickAxis.x;
float vj = MyJoystick.JoystickAxis.y;

animator.SetFloat("Speed", hj*hj+vj*vj*100);
animator.SetFloat("Direction", hj, DirectionDampTime, Time.deltaTime);

}     
}

}

Offline Nicolas

  • Administrator
  • Hero Member
  • *****
  • Posts: 792
Re: Easy Joystick & input.getaxis
« Reply #9 on: January 27, 2014, 05:09:23 PM »
Salut,

Ton code semble correct, as tu une erreur ou quelque chose d'autre ?

Offline jbam

  • Newbie
  • *
  • Posts: 5
Re: Easy Joystick & input.getaxis
« Reply #10 on: January 27, 2014, 05:23:56 PM »
Merci Nicolas pour ta r?ponse

ce qui pose probl?me c'est : float hj = MyJoystick.JoystickAxis.x;

qui me retourne : NullReferenceException: Object reference not set to an instance of an object
deplacementougi.Update () (at Assets/scripts/deplacementougi.cs:30

Offline Nicolas

  • Administrator
  • Hero Member
  • *****
  • Posts: 792
Re: Easy Joystick & input.getaxis
« Reply #11 on: January 27, 2014, 10:01:30 PM »
Tu as bien affect? le joystick dans l'inspecteur de ton script ?

Nicolas

Offline jbam

  • Newbie
  • *
  • Posts: 5
Re: Easy Joystick & input.getaxis
« Reply #12 on: January 28, 2014, 12:22:13 PM »
heuuuuuuu . Mince  ;D ;D ;D
Merci beaucoup je savais bien que c??tait une petite connerie :)
Et merci pour easy touch

Offline jbam

  • Newbie
  • *
  • Posts: 5
Re: Easy Joystick & input.getaxis
« Reply #13 on: January 31, 2014, 07:55:47 PM »
j'ai un autre petit soucis :'(
j?esp?re trouver solution ici

Easy joystick fonctionne tr?s bien, je d?place sans aucun probl?me mon perso dans la direction que je veux .
Mais apr?s un Application.LoadLevel
des que je redirige mon easyjoystick j'ai droit ? un

Quote
MissingReferenceException: The object of type 'deplacementougi' has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.

et je comprend pas pourquoi :'( :'(

voici mon code

Code: [Select]
public class deplacementougi : MonoBehaviour {
protected Animator animator;
public float DirectionDampTime = .50f;
public bool ApplyGravity = false;

void OnEnable(){
EasyJoystick.On_JoystickMove += On_JoystickMove;
EasyJoystick.On_JoystickMoveEnd += On_JoystickMoveEnd;
}

void OnDisable(){
EasyJoystick.On_JoystickMove += On_JoystickMove;
EasyJoystick.On_JoystickMoveEnd += On_JoystickMoveEnd;
}

void OnDestroy(){
EasyJoystick.On_JoystickMove += On_JoystickMove;
EasyJoystick.On_JoystickMoveEnd += On_JoystickMoveEnd;
}

void Start ()
{
        animator = GetComponent<Animator>();
if(animator.layerCount >= 2)
animator.SetLayerWeight(1, 1);
}

void On_JoystickMove( MovingJoystick move){

float angle = -90+move.Axis2Angle(true);
transform.rotation  = Quaternion.Euler( new Vector3(0,angle,0));

if (animator) {
animator.SetFloat ("Speed", 1);
}
}

void On_JoystickMoveEnd (MovingJoystick move)
{
if (animator) {
animator.SetFloat ("Speed", 0);
}
}

Offline jbam

  • Newbie
  • *
  • Posts: 5
Re: Easy Joystick & input.getaxis
« Reply #14 on: February 01, 2014, 01:48:30 PM »
j'ai tout repris a z?ro et c'est bon cela fonctionne .
pas trop compris d'ou venais mon bug , vive les d?but sur unity :)
En tout cas un grand merci pour easy touch car cela fonctionne niquel