Alright I’ve been up all night playing around with Unity and i’ve come across another problem that I’m willing to give away Tom Clancy’s The Division for any one who can help me here im too tired n lazy to try solve it lmao
pretty much what I’m trying to do is have the camera rotatable with the player, it’s an aRPG project at the moment it’s like diablo but I want it to be more like runescape how the camera rotates.
The script for the click to move is:
using UnityEngine;
using System.Collections;
public class ClickToMove : MonoBehaviour
{
public float speed;
public CharacterController controller;
private Vector3 position;
public AnimationClip run;
public AnimationClip idle;
public static bool attack;
public static bool die;
// Use this for initialization
void Start ()
{
position = transform.position;
}
// Update is called once per frame
void Update ()
{
if (!attack&&!die)
{
if (Input.GetMouseButton (0))
{
//Locate where the player clicked on the terrain
locatePosition ();
}
//Move player to position
moveToPosition ();
}
else
{
}
}
void locatePosition()
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
if(Physics.Raycast(ray, out hit, 1000))
{
if(hit.collider.tag!="Player"&&hit.collider.tag!="Enemy")
{
position = new Vector3(hit.point.x, hit.point.y, hit.point.z);
}
}
}
void moveToPosition()
{
if (Vector3.Distance (transform.position, position) > 1) {
Quaternion newRotation = Quaternion.LookRotation (position - transform.position, Vector3.forward);
newRotation.x = 0f;
newRotation.z = 0f;
transform.rotation = Quaternion.Slerp (transform.rotation, newRotation, Time.deltaTime * 10);
controller.SimpleMove (transform.forward * speed);
GetComponent<Animation>().CrossFade (run.name);
}
//Game Object not moving
else
{
GetComponent<Animation>().CrossFade (idle.name);
}
}
}
And I’m also using the Smoothfollow.cs script for my main camera, if anyone can fix this for me I’ll give them a free copy of Tom Clancys The Division — thanks!