How do I make my game object move faster?

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;
            }
        }
    }
}

Is Speed a public field on the other object? If so then if you are setting the default value in code it will not necessarily update. You will need to update it in the inspector instead.

The code

GetComponent<Rigidbody>().AddForce(Vector3.forward * Time.deltaTime * Speed, ForceMode.Impulse);

Which is equivalent to what you have should definitely change the speed at which the object is moved.

Thanks you guys. I figured it out after doing some more Google/YouTubing. The gameObject is a Nav Mesh Agent, so it has a “Speed” field under the NavMeshAgent component that is being used to facilitate how fast it’s moving when I apply force.

I’m referencing a “Speed” field that I created via script, which is not changing the NavMesh speed variable, that’s why there’s no change in speed, hence my problem. Face-palm

Where did you change the speed? In hierarchy or in the script? I mean if you change in hierarchy but you initialize the speed in the script… you know what happens