Player movement
My player only moves one direction and does not rotate.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class PlayerMovement : Photon.MonoBehaviour
{
[SerializeField]
public GameObject player;
[SerializeField]
public Vector3 direction = Vector3.zero;
public Animator anim;
[SerializeField]
Vector3 realPosition = Vector3.zero;
[SerializeField]
Quaternion realRotation = Quaternion.identity;
public int moveSpeed; // Movement speed of player (for run just multiply this value)
void Start()
{
anim = GetComponent<Animator>();
}
void FixedUpdate()
{
if (photonView.isMine)
{
localClient();
AnimMovement();
}
else
{
AnimMovement();
}
}
void localClient() // Movement is too OP and rotation isn't working properly.
{
Vector3 dist = direction * moveSpeed * Time.deltaTime;
if (Input.GetKey(KeyCode.W) || (Input.GetKey(KeyCode.S)))
player.transform.position = Vector3.Lerp(player.transform.position, realPosition, 0.1f);
if (Input.GetKey(KeyCode.D) || (Input.GetKey(KeyCode.A)))
player.transform.rotation = Quaternion.Lerp(player.transform.rotation, realRotation, 0.1f);
}
void AnimMovement()
{
if (Input.GetKey(KeyCode.W) || (Input.GetKey(KeyCode.S) || (Input.GetKey(KeyCode.D) || (Input.GetKey(KeyCode.A)))))
{
anim.Play("SSWalkF");
}
else {
anim.Play("1HIdle");
}
}
[PunRPC]
public void sendMove(Vector3 movePos)
{
realPosition = movePos;
}
}
Comment