Skip to content

Instantly share code, notes, and snippets.

@niiicolai
Last active January 3, 2024 05:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niiicolai/f815e98c7d38b39947738b68fc8fa1eb to your computer and use it in GitHub Desktop.
Save niiicolai/f815e98c7d38b39947738b68fc8fa1eb to your computer and use it in GitHub Desktop.
using UnityEngine;
using UnityEngine.AI;
public class Movement : MonoBehaviour
{
[SerializeField]
private Camera camera;
private string groundTag = "Ground";
private NavMeshAgent agent;
private RaycastHit hit;
// Called when a script is enabled
void Start()
{
agent = GetComponent<NavMeshAgent>();
}
// Called once every frame
void Update()
{
if (Input.GetMouseButtonDown(0))
{
Ray ray = camera.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit, Mathf.Infinity))
{
if (hit.collider.CompareTag(groundTag))
{
agent.SetDestination(hit.point);
}
}
}
}
}
@YuneekGames
Copy link

YuneekGames commented Jan 3, 2024

If you mean the travel speed of movement from the original position to raycasted MousePosition then you adjust the agent speed in the inspector

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment