Apparently I forget how to move an object. WTH is going on?

Whenever I use Time.Deltatime here the object moves hilariously slow. These are 3 code snippets I tried. All do the same some how. Also, changing the speed value does absolutely nothing. Even changing to fixed update and Time.FixedDeltatime. What am i doing wrong? This is in the update function and checking for a vertical axis press.

this.transform.position += Vector3.up * speed * Time.deltaTime;
transform.Translate(Vector3.up * speed * Time.deltaTime, Space.Self);
transform.position += new Vector3(inputH, inputV, 0f) * Time.deltaTime * speed;

Changing the speed value should have an effect.

Is it possible that you’re changing the speed value where you declare the public speed field in the script, but in the inspector, the speed value remains the same? Unity will use the value you see in the inspector.

If so, you could try setting the speed value in the inspector, or in the Start or Awake functions instead of at the top where you declare your field.

Alternatively, if you change the value of some public fields in the script and want them to take effect, you can reset the script using the drop down at the top right of the script in the inspector. This will clear all your references though, so you’ll have to hook up everything again.

Failing that, post the whole code, there might be something else going on.

1 Like

Is the object scale correct? If it was imported and 10X larger at scale 1 you may have to set it to 0.1 as I often have to do based on source of .fbx. Time.deltaTime is a really small number and usually with a speed variable what you are doing is saying over the course of one second i want my object to move the distance of the speed.

1 Like

Thank you my friend. I’m setting public float speed variable equal to all different numbers in the script. But for some reason it keeps being 1 in the inspector. Not sure why that is. It should default to what I set it equal to in the script I thought. Anyways, thanks!

1 Like

Yes, it seems strange, but I think it’s so that designers can tweak the numbers of something in the inspector while the game is running without them resetting to default values every time play is pressed. If you’d like them to behave as you expect, assign the numbers in Start instead :slight_smile: