But basically for the movement for my players im using a virtual joystick but for some reason it only works when there is only 1 person on the network. But the person can still move around with the WASD keys. So im really not sure what is going on with it? Bearing in mind that the first player can still move around with the virtual joystick just now any other player but the joystick image does update when the other players move the joystick, just the movement is being applied for some reason? Any help would be amazing!
Here is my code for the joystick positioning but i dont think it is an error with that:
public virtual void OnDrag(PointerEventData pointerData)
{
Vector2 position = Vector2.zero;
if (RectTransformUtility.ScreenPointToLocalPointInRectangle
(backgroundJoyStickImage.rectTransform, pointerData.position,
pointerData.pressEventCamera, out position))
{
//Sets the position of the joystick
position.x = (position.x / backgroundJoyStickImage.rectTransform.sizeDelta.x);
position.y = (position.y / backgroundJoyStickImage.rectTransform.sizeDelta.y);
///<summary>
/// If the joystick is positioned on the right then times the postion and add,
/// if its on the left then times 2 and minus 1
/// </summary>
float x = (backgroundJoyStickImage.rectTransform.pivot.x == 1) ? position.x * 2 + 1 : position.x * 2 - 1;
float y = (backgroundJoyStickImage.rectTransform.pivot.y == 1) ? position.y * 2 + 1 : position.y * 2 - 1;
inputDirection = new Vector2(x, y);
inputDirection = (inputDirection.magnitude > 1) ? inputDirection.normalized : inputDirection;
joyStickImage.rectTransform.anchoredPosition = new Vector2(inputDirection.x * (backgroundJoyStickImage.rectTransform.sizeDelta.x / 3), inputDirection.y * (backgroundJoyStickImage.rectTransform.sizeDelta.y / 3));
}
}
and here is the code when im applying it to the player movement script:
void MovementControls()
{
float inputHor = Input.GetAxis("Horizontal");
float inputVer = Input.GetAxis("Vertical");
Vector2 movement = new Vector2(inputHor, inputVer);
float angle = Mathf.Atan2(inputVer, inputHor) * Mathf.Rad2Deg;
if(playerJoyStick.inputDirection != Vector2.zero)
{
print("ad i here?");
movement = playerJoyStick.inputDirection;
print("This is movement" + movement);
}
playerBody.velocity = movement * speedAmp;
currentVelocity = movement * speedAmp;
}
So yea, im really unsure why the other players who join the network cant move using the joystick. Any help would be greatly appreciated!