- Home /
Question by
DeanDeano · Apr 28, 2017 at 06:00 AM ·
multiplayerraycasthithit.point
Multiplayer player look at hit.point but other players twitch
I have followed the unity multiplayer tutorials and I wanted to make a multiplayer look at mouse point, the issue I have is every player that joins moves slightly when a player changes where he is facing. Really struggling to find what I am missing. any guidance would be greatly appreciated.
I have also tried have the camera disabled and turning it on for local player but does not change anything.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class PlayerlookAt : NetworkBehaviour
{
public bool LookAt;
public float LookSpeed = 1.0f;
void Update () {
if (isLocalPlayer)
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit))
{
Vector3 relativePos = hit.point - transform.position;
relativePos.y = 0;
Quaternion rotation = Quaternion.LookRotation(relativePos);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, LookSpeed);
}
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Cube instantiaes on wrong side of the plane 1 Answer
Raycast is not returning exact number / Mesh is not exact dimensions 2 Answers
[SOLVED] Multiplayer, RaycastHit Scene-Object returns Null Ref Exception on server side 0 Answers
RaycastHit on disabled CharacterController 1 Answer
Unity networking tutorial? 6 Answers