Hello,
So there is 2 parts to this issue… 1. the joystick, I am not sure if its controlling the player/character/object right, I do see it moving vertical and horizontal when moving the joystick… However, when moving the joystick trying to get to move straight up, down, left or right… it never does, it like zig zags or at an angle and never straight down etc… not sure if maybe my code is not right?
below is the joystick code:
public CharacterController2D controller;
public Joystick joyStick;
public float moveSpeed = 40.0f;
public float fastSpeed = 80.0f;
float horizontalMove = 0.0f;
float verticalMove = 0.0f;
public void Update()
{
////horizontal
if (joyStick.Horizontal <= 0.3f && joyStick.Horizontal > 0.0f)
{
horizontalMove = moveSpeed;
}
else if (joyStick.Horizontal >= 0.4f)
{
horizontalMove = fastSpeed;
}
else if (joyStick.Horizontal >= -0.3f && joyStick.Horizontal < 0.0f)
{
horizontalMove = -moveSpeed;
}
else if (joyStick.Horizontal <= -0.4f)
{
horizontalMove = -moveSpeed;
}
else
{
horizontalMove = 0f;
}
//vertical
if (joyStick.Vertical <= 0.3f && joyStick.Vertical > 0.0f)
{
verticalMove = moveSpeed;
}
else if (joyStick.Vertical >= 0.4f)
{
verticalMove = fastSpeed;
}
else if (joyStick.Vertical >= -0.3f && joyStick.Vertical < 0.0f)
{
verticalMove = -moveSpeed;
}
else if (joyStick.Vertical <= -0.4f)
{
verticalMove = -moveSpeed;
}
else
{
verticalMove = 0f;
}
Player_Character.transform.position = transform.position + new Vector3(horizontalMove * Time.deltaTime, verticalMove * Time.deltaTime);
}
so the 2nd issue, I am trying to get the camera to follow the object, however for some reason, its not… its still stays the same place, not sure if its my Hierarchy or code… but below is the cameraMovement code, and screenshot is the Hierarchy of the objects, the Main is canvas, then below that or child of that is the panel… with the panel having everything…
Code below of the camera:
Code (CSharp):
public class CameraFollow : MonoBehaviour
{
public Transform target;
public Vector3 offset;
// Update is called once per frame
void Update()
{
this.transform.position = target.position + offset;
}
}
the screenshot is attached of how i have it Hierarchy… thinking of mobile and also using canvas as one of the main parents to control or display the resolution 1920 x 1080…
hope this helps which I hope we can solve this. image is called Heirarchy_game.png


