Chapter 5.3 : Controller Mapping
In the last post, I shared my point of view in why I chose the designated controller. In this post I'll show you how I input the controls into Unity.
The controls have already been set in Unity under Input.
From there I can either change them into different keypads or refer to them when it comes to scripting.
I would also refer to online sources to know which button the controller has like the one below :
Once I identify which Input I want to use and what's it's mapped button number is, I then start scripting on the characters movement.
Above is partial script that I did that enabled the character to move and attack. Of course in order for me to put in some terms I need to clarify it whether its:
1) Public or Private
2) Bool, Float, Game Object
Notice on the script there are two inputs?
1) Input.GetAxisRaw ("Horizontal") is for program to recognize and access the left and right movement and enable the Keypad Left and Right as well as the controller's Left and Right D-pad to be used.
2) Input.GetAxisRaw ("Vertical") is the same but towards up and down since my game is an up and down RPG style.
FUN FACT : This control can also be used to make the character jump, provided that you need to add in a Rigidbody component to the character and increase it's gravity scale to bring the character down.
3) Input.GetKeyDown is where I put in the designated joystick button to work. I would put in the rest of the functions in the bracket provided for it to work.
Some people prefer to use analog to move the character however I was unable to make it work due to the clashing between two inputs in Unity. I'll try to work on that and post it in the upcoming posts :)
The controls have already been set in Unity under Input.
From there I can either change them into different keypads or refer to them when it comes to scripting.
I would also refer to online sources to know which button the controller has like the one below :
Once I identify which Input I want to use and what's it's mapped button number is, I then start scripting on the characters movement.
Above is partial script that I did that enabled the character to move and attack. Of course in order for me to put in some terms I need to clarify it whether its:
1) Public or Private
2) Bool, Float, Game Object
Notice on the script there are two inputs?
1) Input.GetAxisRaw ("Horizontal") is for program to recognize and access the left and right movement and enable the Keypad Left and Right as well as the controller's Left and Right D-pad to be used.
2) Input.GetAxisRaw ("Vertical") is the same but towards up and down since my game is an up and down RPG style.
FUN FACT : This control can also be used to make the character jump, provided that you need to add in a Rigidbody component to the character and increase it's gravity scale to bring the character down.
3) Input.GetKeyDown is where I put in the designated joystick button to work. I would put in the rest of the functions in the bracket provided for it to work.
Some people prefer to use analog to move the character however I was unable to make it work due to the clashing between two inputs in Unity. I'll try to work on that and post it in the upcoming posts :)
Comments
Post a Comment