0

Here is the code:

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class Player : MonoBehaviour { //Variables public float movementSpeed; public GameObject playerMovePoint;

 private Transform pmr;
 private bool pmrSpawned;
 private bool moving;
 //Functions
 void Update()
 {
  //Player Movement
  Plane playerPlane = new Plane(Vector3.up, transform.position);
  Ray ray = UnityEngine.Camera.main.ScreenPointToRay(Input.mousePosition);
  float hitDistance = 0.0f;
  if (playerPlane.Raycast(ray, out hitDistance))
  {
   Vector3 mousePosition = ray.GetPoint(hitDistance);
   //Quarternion targetRotation = Quarternion.LookPosition(mousePosition - transform.position);
   if (Input.GetMouseButtonDown(0))
   {

     moving = true;

     if (pmrSpawned)
     {
     pmr = null;
     pmr = Instantiate(playerMovePoint.transform, mousePosition, Quaternion.identity);
     }else{
     pmr = Instantiate(playerMovePoint.transform, mousePosition, Quaternion.identity);
     }


  }
 }
 if (pmr)

  pmrSpawned = true;
 else
     pmrSpawned = false;
 if (moving)

     transform.position = Vector3.MoveTowards(transform.position, pmr.transform.position, 0.5f);

 }

}

Im trying to make an RPG and i want my character to move. Im trying to get my character to move to where my mouse is clicked. I cant seem to find anything online to fix it.

jmarkmurphy
  • 9,829
  • 28
  • 51

0 Answers0