Below is my ClickToMove script, which makes the game object (a sphere) move to a point on a Nav Mesh. I’ve tried to change the “Speed” (which I am getting from the object “Golem”) from 5 to 15, to 100, but the game object is still moving at the same pace. I don’t understand why. Anyone have an idea?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class ClickToMove : MonoBehaviour
{
NavMeshAgent agent;
private Rigidbody rb;
// Start is called before the first frame update
void Start()
{
agent = GetComponent<NavMeshAgent>();
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
float movementHorizontal = Input.GetAxis("Horizontal");
float movementVertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(movementHorizontal, 0.0f, movementVertical);
rb.AddForce(movement * GetComponent<Golem>().Speed * Time.deltaTime);
if (Input.GetMouseButtonDown(0))
{
RaycastHit hit;
if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition),out hit, 100))
{
agent.destination = hit.point;
}
}
}
}