Question by
porops312 · Jun 04, 2016 at 03:53 PM ·
unity5joystickcharacter controllercharacter movement
Unity Character Controller for Mobile Device
I'm New in Unity 3D Programming, i just follow tutorial from survival shooter and try to add some mobile device joystick controller
why when i want to rotate the character with right joystick, when the analog is drag left (around 270-290 degree) and drag right (around 90 degree) the character is facing down, like image below.
Here is the code :
PlayerMovement script :
void FixedUpdate ()
{
transform.Translate(Time.deltaTime * new Vector3(JoystickMove.instance.H, 0f, JoystickMove.instance.V) * speed * Time.deltaTime);
Turning ();
Animating (JoystickMove.instance.H, JoystickMove.instance.V);
}
void Turning ()
{
transform.LookAt(transform.position + new Vector3(JoystickRotate.instance.H, 0f, JoystickRotate.instance.V));
}
and the JoystickRotate script
public class JoystickRotate : JoystickMove
{
public static JoystickRotate instance=null;
void Awake(){
if(instance!=null){
Destroy(this.gameObject);
}else{
instance=this;
}
}
}
Hope someone can Help :D
joystick.png
(284.9 kB)
Comment
Your answer
Follow this Question
Related Questions
infamous first light run code help 1 Answer
Trying to figure out WallRiding, with Vector3.Cross 0 Answers
I can't seem to get this movement + automatic lookat the direction of movement work for a 2.5D game 0 Answers
Why does my character randomly move right? 0 Answers
Character controller does not jump 1 Answer