Home>
Started writing a 2d game in Unity. I am studying movement through the joystick (for android). All is well, moving left and right. But I can't figure out what needs to be done to make the object move up and down.
Here is my code:
public Joystick joystick;
private int speed= 4;
private float moveInput;
public Rigidbody2D rb;
public void FixedUpdate ()
{
moveInput= joystick.Horizontal;
rb.velocity= new Vector2 (moveInput * speed, 0);
}
UPD: Thanks to the answer, I'll make the edit. Here's what I added:
private float moveInput1;
moveInput1= joystick.Vertical;
rb.velocity= new Vector2 (moveInput * speed, moveInput1 * speed);
-
Answer # 1
-
Answer # 2
Mmm ...
To interrogatejoystick.Vertical;
and to set the second component of speed?
Related questions
- c# : Unity | Can't add getting coins for watching rewarded ads
- c# : Inheriting a component from a superclass
- c# : KeyNotFoundException: The given key was not present in the dictionary
- c# : The Strategy pattern in Unity. How to fit the logic of click-to-move motion into this pattern?
- c# : Overlay background on top of each other
- c# : Incorrect Unity3D motion calculation
- c# : InvalidCastException: Specified cast is not valid
- c# : How do I get a component in Unity through a string variable?
- c# : Is it correct to write logic in scriptableObject?
Mmm ...
To interrogate
joystick.Vertical;
and to set the second component of speed?