Movement Script Affecting Other Player's Movement

Hey all,

In a game where four players should move independently around a circle, if right movement for one character and left movement for another character happen at the same time, they move in the same direction, rather than around the circle in the proper way.

We have WASD and the arrow keys for movement in this scenario, and they seem to be mapped properly through input manager. However, the problem still persists.

I feel one of our variables is affecting the movement in a way we are not understanding.

Any help would be greatly appreciated. Thanks!

NOTE: The script for this player’s movement is identical to the other player’s scripts, where the only difference is the action key. (WASD, arrow keys, J and L for right/left, and [4] and [6] for right/left)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/// <summary>
/// Player controller and behavior
/// </summary>
public class Player2Script : MonoBehaviour
{
    /// <summary>
    /// 1 - The speed of the ship
    /// </summary>

    // 2 - Store the movement and the component
    private Vector2 movement2;
    private Rigidbody2D rigidbodyComponent;
    float timeCounter = 0;
    void Update()
    {
        // 3 - Retrieve axis information
        //timeCounter += Time.deltaTime;

        if (Input.GetKey("j"))
        {
            RotateLeft();
        }
        if (Input.GetKey("l"))
        {
            RotateRight();
        }
    }

    void FixedUpdate()
    {
        // 5 - Get the component and store the reference
        if (rigidbodyComponent == null) rigidbodyComponent = GetComponent<Rigidbody2D>();

        // 6 - Move the game object
        rigidbodyComponent.velocity = movement2;
    }

    void RotateLeft()
    {
        timeCounter += Input.GetAxis("Horizontal") * Time.deltaTime * 4; // multiply all this with some speed variable (* speed);
        float x = Mathf.Cos(timeCounter) * 4;
        float y = Mathf.Sin(timeCounter) * 4;
        float z = 0;
        transform.position = new Vector3(x, y, z);
        transform.Rotate(Vector3.forward * -4);
    }

    void RotateRight()
    {
        timeCounter += Input.GetAxis("Horizontal") * Time.deltaTime * 4; // multiply all this with some speed variable (* speed);
        float x = Mathf.Cos(timeCounter) * 4;
        float y = Mathf.Sin(timeCounter) * 4;
        float z = 0;
        transform.position = new Vector3(x, y, z);
        transform.Rotate(Vector3.forward * 4);
    }
}

@shimbobular, You are doing two kinds of ‘rotation’ so perhaps the issue seems confusing. The player object ‘revolves’ around the circle’s center, and also ‘rotates’ about the center of it’s own axis.

The rotate code is correctly aligned with the apparent intent: rotate right 4, rotate left -4.

but the problem is the revolve code: You have the exact same code for both left and right revolve motion based on horizontal input. Therefore all the players will revolve in exactly the same direction around the circle no matter which way they rotate.