- Home /
Question by
xXEpicKingXx · May 30 at 06:15 PM ·
unity 2dplayer movement
Player movement script based on a given symmetry
I'm trying to make a game where the movement of the second player is based on the first player's movement but with a given line of symmetry. For example, if the inputted symmetry was y=x, then when player 1 moves to the left, player 2 moves down. Problem is, I'm a novice and don't know how to do that. Can someone help me figure out what I need to change in my script to achieve this?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
// Start is called before the first frame update
public float moveSpeed = 5f;
public Rigidbody2D rb;
public Animator animator;
Vector2 movement;
// Update is called once per frame
void Update()
{
movement.x = Input.GetAxisRaw("Horizontal");
movement.y = Input.GetAxisRaw("Vertical");
animator.SetFloat("Horizontal", movement.x);
animator.SetFloat("Vertical", movement.y);
animator.SetFloat("Speed", movement.sqrMagnitude);
}
void FixedUpdate()
{
rb.MovePosition(rb.position + movement * moveSpeed * Time.fixedDeltaTime);
}
}
Comment