- Home /
click to move workig script!! but pls help with rotation!! :(
hi I done same basic script n It's WORKING but I can't get smooth rotation n moment :(
like also can u check serialization pls :)
code: using UnityEngine; using System.Collections;
public class Pcontllorer : MonoBehaviour {
public float PlayerMoveSpeed;
private Vector3 TargetPosition;
void Start () {
if (!networkView.isMine)
{
enabled = false;
TargetPosition = transform.position;
}
}
void Update () {
if (networkView.isMine)
{
if (Input.GetMouseButtonDown(0))
{ Plane playerPlane = new Plane(Vector3.up, transform.position); Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); float hitdist = 0.0f;
if (playerPlane.Raycast(ray, out hitdist))
{
Vector3 targetPoint = ray.GetPoint(hitdist);
TargetPosition = ray.GetPoint(hitdist);
Quaternion targetRotation = Quaternion.LookRotation(targetPoint - transform.position);
transform.rotation = targetRotation;
}
}
transform.position = Vector3.Lerp(transform.position, TargetPosition, Time.deltaTime * PlayerMoveSpeed);
} }
void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
{ if (stream.isWriting) { Vector3 pos = transform.position; stream.Serialize(ref pos); } else { Vector3 posRec = Vector3.zero; stream.Serialize(ref posRec); transform.position = posRec; } } }
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
How do I move the player towards the direction of the camera using cinemachine? 0 Answers
Help with my Character Controller 1 Answer
How to properly set the position clicked by the mouse? 0 Answers
Unity 8-Directional Locked Movement (Super Mario 3D World Style) 3 Answers