Hi there, so I’m trying to use the Joystick Pack that you can find on the asset store for free, and basically I just want to have a joystick that shows up at the specific touch position when only on the left side of the screen, and on the right side of the screen I just want the player to be able to tap to jump.
I’ve been trying many ways for weeks to get this to work, I actually came very close with my custom script but both the outer container and the inner container were always stuck together.
This is the Floating Joystick script where I think I need to do the editing, I’m not sure:
public class FloatingJoystick : Joystick
{
protected override void Start()
{
base.Start();
background.gameObject.SetActive(false);
}
public override void OnPointerDown(PointerEventData eventData)
{
background.anchoredPosition = ScreenPointToAnchoredPosition(eventData.position);
background.gameObject.SetActive(true);
base.OnPointerDown(eventData);
}
public override void OnPointerUp(PointerEventData eventData)
{
background.gameObject.SetActive(false);
base.OnPointerUp(eventData);
}
}
And here is part of my attempt before this (it’s very messy I’m sorry):
public void Update() {
for (int i = 0; i < Input.touchCount; i++)
{
Vector2 touchPosition = Input.touches*.position;*
if (touchPosition.x < Screen.width/2)
-
{*
pointA = Camera.main.ScreenToWorldPoint(new Vector3(touchPosition.x, touchPosition.y, Camera.main.transform.position.z));
pointB = Camera.main.ScreenToWorldPoint(new Vector3(touchPosition.x, touchPosition.y, Camera.main.transform.position.z));
circle.transform.position = pointA;// * -1;
outerCircle.transform.position = pointB;// * -1;
circle.GetComponent().enabled = true;
outerCircle.GetComponent().enabled = true;
touchStart = true;
}
-
if (touchPosition.x > Screen.width/2)*
-
{*
-
keyPressed = true;*
-
}*
-
else*
-
{*
-
keyPressed = false;*
}
-
}*
}
void FixedUpdate()
{
if (touchStart)
{
Vector2 offset = pointB - pointA;
Vector2 direction = Vector2.ClampMagnitude(offset, 1.0f);
circle.transform.position = new Vector2(pointA.x + direction.x, pointA.y + direction.y) * -1;
}
else
{
touchStart = false;
circle.GetComponent().enabled = false;
outerCircle.GetComponent().enabled = false;
}
}
Any help is greatly appreciated, thank you!