- Home /
Question by
OpSyKi · Apr 06, 2020 at 03:24 PM ·
movementmultiplayertop down shooter
Multiplayer Movement
I want to make a top down shooter multiplayer game with mirror. Every time I use (!isLocalPlayer) the player is motionless
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class PlayerMovement : NetworkBehaviour
{
public float movespeed = 2f;
public Rigidbody2D rb;
Vector2 movement;
Vector2 mousepos;
public Camera cam;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
[Client]
void Update()
{
if (!isLocalPlayer)
{
return;
}
movement.x = Input.GetAxisRaw("Horizontal");
movement.y = Input.GetAxisRaw("Vertical");
mousepos = cam.ScreenToWorldPoint(Input.mousePosition);
}
void FixedUpdate()
{
rb.MovePosition(rb.position + movement * movespeed * Time.fixedDeltaTime);
Vector2 lookDir = mousepos - rb.position;
float angle = Mathf.Atan2(lookDir.y, lookDir.x) * Mathf.Rad2Deg - 90f;
rb.rotation = angle;
}
}
Comment
Your answer
Follow this Question
Related Questions
Player won't look in direction and travel at the same time? 2 Answers
How would I continue an object's movement in the same direction as per last user input? 1 Answer
How to handle movement in a multiplayer FPS? 0 Answers
How to determine 2D Directional animation based on player direction in a top down game 1 Answer